C#.NET Generating web service reference using WSDL (from XML schema) problem

我们两清 提交于 2020-01-05 03:48:10

问题


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:


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>


来源:https://stackoverflow.com/questions/7000474/c-net-generating-web-service-reference-using-wsdl-from-xml-schema-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!