[英]C#.NET Generating web service reference using WSDL (from XML schema) problem
I am using VS2010 and using the "add service reference" feature, to generate client classes from my WSDL.我正在使用 VS2010 并使用“添加服务引用”功能从我的 WSDL 生成客户端类。 I am having a problem with one of my elements, which is defined in the WSDL as follows:我的一个元素有问题,它在 WSDL 中定义如下:
<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.问题是 VS 将这个特定元素转换为字符串类型,而它应该是一个枚举。 so it converts it to a string NumberTypes which has a get method returning numberTypesField also of type string.所以它将它转换为一个字符串 NumberTypes,它有一个 get 方法返回 numberTypesField 也是字符串类型。
I think the problem is related to the fact that my schema NumberTypes element uses the xs:list, with 'itemType' attribute.我认为问题与我的架构 NumberTypes 元素使用 xs:list 和“itemType”属性有关。 if I change this to xs:element with type="tns:NumberType" attribute instead then the enumeration is generated as it should be.如果我将其更改为带有 type="tns:NumberType" 属性的 xs:element ,则将按应有的方式生成枚举。
So how can I make the enumeration work with xs:list?那么如何使枚举与 xs:list 一起工作呢? Why is it not converting correctly in the first place?为什么它一开始就不能正确转换?
Thanks for any help.谢谢你的帮助。
I haven't had much luck getting xs:list to serialize properly.我没有太多运气让 xs:list 正确序列化。 Instead, I just allow for multiple instances of the same node, and .NET knows how to put it into a "list" or "array" properly.相反,我只允许同一节点的多个实例,并且 .NET 知道如何正确地将其放入“列表”或“数组”中。
<xs:element minOccurs="0" maxOccurs="unbounded" name="NumberTypes">
...
</xs:element>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.