使用WSDL(从XML模式)C#.NET生成Web服务引用问题 [英] C#.NET Generating web service reference using WSDL (from XML schema) problem
问题描述
我使用VS2010和使用添加服务引用功能,从我的WSDL生成客户端类。我有我的元素,这是在WSDL定义中的一个问题,如下所示:
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>
的问题是,VS是这个特定元素转换为字符串类型,当它应该是枚举。所以它转换为字符串NumberTypes其中有一个get方法也返回字符串类型的numberTypesField。
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.
我认为这个问题是关系到我的架构NumberTypes元素使用XS的事实:列表中,用ITEMTYPE'属性。如果我更改为XS:元素具有type =TNS:NumberType属性,而不是那么枚举生成的,它应该是
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.
所以,我怎样才能使统计工作与XS:名单?为什么不能正确转换摆在首位?
So how can I make the enumeration work with xs:list? Why is it not converting correctly in the first place?
感谢您的帮助。
推荐答案
我没有多少运气得到的xs:名单序列化正确。相反,我只允许在同一个节点的多个实例,以及.NET知道如何把它变成一个名单或阵列正常。
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>
这篇关于使用WSDL(从XML模式)C#.NET生成Web服务引用问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!