Reputation: 1373
I'm developing for Windows Mobile and so have to use Web Services rather than WCF. I have a business object that I pass via the web service which works fine except for one property that is an enum. This value always appears on the server as the default value no matter what the client has set it to. Very confused :(
Here's the code in the business object defined on the server:
public enum TaskTypeEnum { GoodsReceipt, ImportCosting };
[Serializable, DataContractAttribute]
public class TaskContainer
{
[DataMemberAttribute]
public TaskTypeEnum TaskType { get; set; }
...
And here's the code on the client that sets this property:
var container = new TaskContainer();
container.TaskType = TaskTypeEnum.ImportCosting;
service.Save(container);
For some unknown reason when this "container" object gets to the server, the TaskType property is always set to GoodsReceipt no matter what I have set it to on the client.
Thanks for the help.
Upvotes: 3
Views: 1206
Reputation: 3089
I had a similar problem. In the proxy class fields of primitive types (i.e. non nullable fields) have a second field called Specified.
Perhaps in your case TaskContainer has a field called TaskTypeSpecified. Try setting
container.TaskTypeSpecified = true;
Upvotes: 0
Reputation: 27055
You need to make sure that your enum also has a DataContract, otherwise it will not be serialized, and each member must have the attribute EnumMember
[DataContract]
public enum TaskTypeEnum
{
[EnumMember]
GoodsReceipt,
[EnumMember]
ImportCosting
}
Also see: http://msdn.microsoft.com/en-us/library/aa347875.aspx
Upvotes: 6