{
Black=-1,
Red=0,
Green=1,
Blue=2
}
The numeric values are stored in a database.
My problem is that on the client side (proxy auto generated code) the enum no longer has the non-default values assigned. Therefore it effectively becomes:
public enum MyEnum
{ Black=0,
Red=1,
Green=2,
Blue=3 }
But the value that actually travels across the http wire is the numeric! So all the values become misinterpreted(!!!!)
I need the database to record numeric, and either the proxy code to retain the non-default values, or for the http to pass the labels instead of the values.
To my mind the only valid values to go over the wire are the literals Black, Red, Green and Blue. Anything else should fail xml validation. It appears the XML is not validated against the auto generated schema in the wsdl???
None
0 Points
19 Posts
Is it possible to preserve enum semantics over XmlSerialization, when non-default enum values are...
Oct 21, 2014 12:31 PM|Martin0|LINK
I've got an enum declared like so:
public enum MyEnum
{
Black=-1,
Red=0,
Green=1,
Blue=2
}
The numeric values are stored in a database.
My problem is that on the client side (proxy auto generated code) the enum no longer has the non-default values assigned. Therefore it effectively becomes:
public enum MyEnum
{ Black=0,
Red=1,
Green=2,
Blue=3 }
But the value that actually travels across the http wire is the numeric! So all the values become misinterpreted(!!!!)
I need the database to record numeric, and either the proxy code to retain the non-default values, or for the http to pass the labels instead of the values.
Any tips much appreciated.
Kind Regards
Martin
Enums XmlSerialization
None
0 Points
19 Posts
Re: Is it possible to preserve enum semantics over XmlSerialization, when non-default enum values...
Oct 21, 2014 01:28 PM|Martin0|LINK
I am surprised to see the values going the http wire as numeric values, when the wsdl declares them as with a type like this:
<s:simpleType name="MyEnum">
<s:restriction base="s:string">
<s:enumeration value="Black" />
<s:enumeration value="Red" />
<s:enumeration value="Green" />
<s:enumeration value="Blue" />
</s:restriction>
</s:simpleType>
To my mind the only valid values to go over the wire are the literals Black, Red, Green and Blue. Anything else should fail xml validation. It appears the XML is not validated against the auto generated schema in the wsdl???
PS I am using .Net 2.0 and asmx
Enums XmlSerialization
None
0 Points
19 Posts
Re: Is it possible to preserve enum semantics over XmlSerialization, when non-default enum values...
Oct 22, 2014 03:52 AM|Martin0|LINK
Solved - somewhere deep in the code there were properties that were declared as int rather than the enum (Doh!! & ouch)
Enums XmlSerialization
Participant
1398 Points
219 Posts
Re: Is it possible to preserve enum semantics over XmlSerialization, when non-default enum values...
Oct 22, 2014 04:27 AM|May Wang|LINK
Hi,
Thanks for sharing your solution.
May
Enums XmlSerialization