none
Web Service Enum Limitation RRS feed

  • Question

  • Hi,

    We are able to consume Web Service which has got list of Enumeration constants. After Consuming, the actual Enum values are translated to default values. As a result, if we perform some operation to Enums, it is failing.

    When enumeration type is used in .net web service, the string name of the enumeration value is used but not the underlying integer. We are getting an exception for all the ENUM’s.

     

    *********************1

    XSD details

    <xs:simpleType name="StatusID">

    <xs:restriction base="xs:string">

    <xs:enumeration value="1"/>

    <xs:enumeration value="2"/>

    <xs:enumeration value="3"/>

    <xs:enumeration value="4"/>

    <xs:enumeration value="9"/>

    </xs:restriction>

    </xs:simpleType>

     

    MetaData Detail:

         public enum StatusID

        {

            [XmlEnum("1")]

            Item1 = 0,

            [XmlEnum("2")]

            Item2 = 1,

            [XmlEnum("3")]

            Item3 = 2,

            [XmlEnum("4")]

            Item4 = 3,

            [XmlEnum("9")]

            Item9 = 4,

        }

    Kindly suggest....

    Tuesday, September 17, 2013 8:18 AM

Answers

  • The author of the service is overriding the C# enum structure, and providing their own values (by using XmlEnum) for serialization.  In other words, consumers of the service will no longer have access to the underlying enum values that were originally in the C# code.  If the author of the service wanted to provide access to original enum structure, the enum would have to be coded in as per the example below.  Then, Enum values could be accessed in the format Item1, Item2, etc.  I'm not sure if WCF will still recognize the integer values of the enum - it may only recognize the actual names as they exist in the code.  As long as the names of the enum members are passed through the web service, it will work using the code below.

    [DataContract]
    public enum StatusID
    
        {
    
            [EnumMember]
            Item1 = 0,
    
            [EnumMember]
            Item2 = 1,
    
            [EnumMember]
            Item3 = 2,
    
            [EnumMember]
            Item4 = 3,
    
            [EnumMember]
            Item9 = 4,
    
        }

    Tuesday, September 17, 2013 12:41 PM