C#.NET Generating web service reference using WSDL

2019-08-04 02:17发布

I am using VS2010 and using the "add service reference" feature, to generate client classes from my WSDL. I am having a problem with one of my elements, which is defined in the WSDL as follows:

<xs:simpleType name="NumberType">
    <xs:restriction base="xs:string">
        <xs:enumeration value="ONE" /> 
        <xs:enumeration value="TWO" /> 
        <xs:enumeration value="THREE" /> 
    </xs:restriction>
</xs:simpleType>

This type is used in one of my elements like this:

<xs:element name="NumberTypes">
    <xs:simpleType>
        <xs:list itemType="tns:NumberType" /> 
    </xs:simpleType>
</xs:element>

The problem is that VS is converting this particular element to a string type, when it should be an enumeration. so it converts it to a string NumberTypes which has a get method returning numberTypesField also of type string.

I think the problem is related to the fact that my schema NumberTypes element uses the xs:list, with 'itemType' attribute. if I change this to xs:element with type="tns:NumberType" attribute instead then the enumeration is generated as it should be.

So how can I make the enumeration work with xs:list? Why is it not converting correctly in the first place?

Thanks for any help.

1条回答
放荡不羁爱自由
2楼-- · 2019-08-04 02:52

I haven't had much luck getting xs:list to serialize properly. Instead, I just allow for multiple instances of the same node, and .NET knows how to put it into a "list" or "array" properly.

<xs:element minOccurs="0" maxOccurs="unbounded" name="NumberTypes">
    ...
</xs:element>
查看更多
登录 后发表回答