Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I define a constant in a Web Service interface

Status
Not open for further replies.

WillyWonka404

Programmer
May 1, 2003
2
US
I am using a web service coded in C#. There are classes and an enum type in the interface. I want to define a constant that the client can set as one of the properties of a class on the interface. It's a magic number and I want to provide it as a contant on the interface.

I added the contstant declaration to one of the classes. All the non-const properties of the class appear as class properties in the WSDL. The client can get/set them. But the constant I declare right along side the properties does not appear in the WSDL and is not accessible to the client.


Here's what the class looks like. Everything works except the constant is not available to the client.

public class MyClass
{
public int ID; //Required
public string ShippingAttentionLine;
public string ShippingAddressLine1;
public string ShippingCity;
public string ShippingState;
public string ShippingZipCode;
public int ShippingMethod;
public const int DONT_CARE = 1;
}

 
Try declaring it as a property.

If that works, you might want to watch out for multiple network round-trips - they'll slow you down.

Chip H.
 
Thanks for the suggestion, but it did not work. I added a few new public members and declared my contstant as a property. The new members show up in the WSDL (so I know everything is compiling in both applications), but the new property did not.

The property is declared as:

public int DONT_CARE
{
get
{
return 1;
}
}
 
You could define a function that acts like a property:
Code:
public int DONT_CARE()
{
   return 1;
}
But I'm thinking it might be easier just to write it up in the documentation, and throw an error if they give you an unexpected value.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top