Wcf Serialize Flags Enum

4/27/2018by admin

Hello, this is not supported out of box by DataContractSerializer. 8dio 1928 Steinway Legacy Piano more. You can use XmlSerializer if you like.

XmlSerializer should give you more control over the serializing process. However, I wonder why you need to put the intger value in the serialized message. Usually if intger values are stored in database, you only want to deal with intgers inside the service, and clients should not know 1 represents None, 2 represents Email, etc. Clients are only interested in the text representation.

Wcf Serialize Flags Enum

I have a Windows Phone app that connects to a WCF service. The WCF service has a Login() method that accepts the username and password, then returns a Flags Enum. Feb 17, 2011 Hi, I am facing an critical problem in Enum serialization in WCF. Here is the scenario: I have an enum like this. [Serializable] [DataContract (Namespace.

They don't care how to actaully store the data. Lante, shanaolanxing This posting is provided 'AS IS' with no warranties, and confers no rights.

Hi, I've tried your code, I've enabled tracing and this is what I get: There was an error while trying to serialize parameter. The InnerException message was 'Enum value '0' is invalid for type 'ActionReportResponse' and cannot be serialized. Ensure that the necessary enum values are present and are marked with EnumMemberAttribute attribute if the type has DataContractAttribute attribute.' Please see InnerException for more details. The problem here is that you're not initializing the ActionReportResponse and it is taking the default (and invalid) value of '0'.

So it cannot be serialized. Add some valid default value for this member in your constructor or define some Default enum member with value '0' and it will work ok. Regards, Rodrigo. Hi, I've tried your code, I've enabled tracing and this is what I get: There was an error while trying to serialize parameter. The InnerException message was 'Enum value '0' is invalid for type 'ActionReportResponse' and cannot be serialized. Ensure that the necessary enum values are present and are marked with EnumMemberAttribute attribute if the type has DataContractAttribute attribute.' Please see InnerException for more details.

The problem here is that you're not initializing the ActionReportResponse and it is taking the default (and invalid) value of '0'. So it cannot be serialized.

Add some valid default value for this member in your constructor or define some Default enum member with value '0' and it will work ok. Regards, Rodrigo. As a late follow up, the answer on this post was indeed helpful, but I found that adding a '0' value to the Enum was the only working solution. Adding a statement to the constructor of the class setting a default value didn't even get processed by the proxy on the client, and the exception was still thrown.

Cfm56 7 Manual there. Only when a value of '0' was added to the enum did the problem get solved. Of course this is only an issue if the client has chosen not to populate the enum property and leave it as its default value.