I have defined the following enum on the WCF server side:
[DataContract]
public enum CarConditionEnum {
[EnumMember]
New,
[EnumMember]
Used,
[EnumMember]
Rental,
[EnumMember]
Broken,
[EnumMember]
Stolen
}
The operation contract method interface method I will use, also server-side:
[OperationContract]
string WhatEnumDidIUse(CarConditionEnum carCondition);
The method implementation for this interface (server-side):
public string WhatEnumDidIUse(CarConditionEnum carCondition) {
return carCondition.ToString();
}
When I generate a proxy to this service dynamically, the method it generates looks like this (and I’m pretty sure it’ll look the same if I generate it using a web reference):
/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/IService1/WhatEnumDidIUse", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
[return: System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
public string WhatEnumDidIUse(CarConditionEnum carCondition, [System.Xml.Serialization.XmlIgnoreAttribute()] bool carConditionSpecified) {
object[] results = this.Invoke("WhatEnumDidIUse", new object[] {carCondition, carConditionSpecified});
return ((string)(results[0]));
}
Why is there now this boolean to specify that the enumerable has been specified?
Also, why does this boolean behave strangely? For example, if I set the boolean argument to false, my method will always return the first enumerable, New. If I set the boolean argument to true, it will return whatever enumerable I actually specified.
This is because the boolean indicates whether or not the enum parameter has been supplied. If not, then it will behave as though you had supplied the enum with integer value zero.
Having said that, I don’t understand why the “*specified” is there. The enum must always be present, based on your code. If you had specified
CarConditionEnum?, then I would understand it.Are you sure this is a WCF service? That looks like an ASMX prologue.