将 WSDL 导入到 Visual Studio 时出现枚举问题
我有一个像这样在 WSDL 中声明的枚举
<xsd:simpleType name="KopRate">
<xsd:annotation>
<xsd:documentation>Information</xsd:documentation>
</xsd:annotation>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="0" />
<xsd:enumeration value="13" />
<xsd:enumeration value="21" />
<xsd:enumeration value="56" />
<xsd:enumeration value="ts" />
<xsd:enumeration value="kp" />
</xsd:restriction>
</xsd:simpleType>
问题是 Visual Studio 生成一个像这样的枚举类(添加这个“Item”单词):
namespace TestNmsp
{
[GeneratedCode("System.Xml", "4.0.30319.1")]
[XmlType(Namespace = "http://www.kop.com/test/schema")]
[Serializable]
public enum KopRate
{
[XmlEnum("0")] Item0,
[XmlEnum("13")] Item13,
[XmlEnum("21")] Item21,
[XmlEnum("56")] Item56,
ts,
kp,
}
}
当然,我希望有一个没有这个“Item”部分的枚举。为什么会发生这种情况,我该如何克服?
I have an enumeration declared in WSDL like this
<xsd:simpleType name="KopRate">
<xsd:annotation>
<xsd:documentation>Information</xsd:documentation>
</xsd:annotation>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="0" />
<xsd:enumeration value="13" />
<xsd:enumeration value="21" />
<xsd:enumeration value="56" />
<xsd:enumeration value="ts" />
<xsd:enumeration value="kp" />
</xsd:restriction>
</xsd:simpleType>
The problem is Visual Studio generates an enumeration class like this (adding this 'Item' word):
namespace TestNmsp
{
[GeneratedCode("System.Xml", "4.0.30319.1")]
[XmlType(Namespace = "http://www.kop.com/test/schema")]
[Serializable]
public enum KopRate
{
[XmlEnum("0")] Item0,
[XmlEnum("13")] Item13,
[XmlEnum("21")] Item21,
[XmlEnum("56")] Item56,
ts,
kp,
}
}
Of course I would like to have an enumeration without this 'Item' part. Why this is happening and how can I pass that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
添加 Item 一词的原因如下:
对于 C# 语法无效。保持 WSDL 能够反序列化可能值的解决方法是添加字母或其他内容作为前缀。在本例中为“Item”一词。
如果您可以控制 WSDL,建议更改枚举的值以遵守命名约定。
如果您无法控制 WSDL。您始终可以根据需要更改枚举,但保留 XMLEnum 属性,以便让反序列化过程正常工作。
例如:
请注意,如果您重新生成代理,您将丢失此更改。
问候,
The reason because the word Item is being added is because the following:
Is not valid for C# Syntax. The workaround to keep the WSDL as is an be able to deserialize the possible values is to add a letter or something as a prefix. In this case the "Item" word.
If you have control over the WSDL, It's recommended to change the values of the enumeration in order to respect the naming conventions.
If you do not have control over the WSDL. You can always change the enumeration as you want, but keeping the XMLEnum attribute, in order to let the deserialization process work correctly.
e.g.:
Please be aware that if you regenerate the proxy you will lose this change.
Regards,