I am defining a web service which calls a service library. The service library has an object called customer with a customer ID defined the following way:
public class Customer
{
private int _customerID;
public int CustomerID
{
get { return _customerID; }
}
}
When I try to pass a customer object back through my web service, it seems that the WSDL generated doesn't include the property CustomerID, unless I define a setter. It seems like requiring a setter is undesireable in certain circumstances. Am I missing something, or does generating a WSDL require a property to have a getter/setter in order to be exposed to the client?
The other answers are correct, but don't mention that this is a restriction of the XML Serializer, which is used by ASMX web services.
ASMX web services are now considered by Microsoft to be "legacy technology", and should not be used for new service development. Their replacement, WCF, does not have this restriction.