WSDL、Enums 和 C#:仍然很模糊
我试图在网上查找这一点,但所有 WSDL 示例似乎都没有真正解释我是否应该将事物标记为 WSDL 或 int 中的基本类型字符串...
基本上,我正在尝试制作我的 WSDL,以便我可以表示枚举。我心里已经有一个 C# 枚举,我想将它匹配...
public enum MyEnum {
Item1 = 0,
Item2 = 1,
Item3 = 2,
SpecialItem = 99
}
我不确定我的 WSDL 应该是什么样子...我认为它是两个之一,但即使这样我也不是 100% 确定。 ..
<wsdl:types>
<xsd:schema targetNamespace="http://www.mysite.com/MyApp"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>
<xsd:simpleType name="MyEnum">
<xsd:restriction base="xsd:int">
<xsd:enumeration value="0" />
<xsd:enumeration value="1" />
<xsd:enumeration value="2" />
<xsd:enumeration value="99" />
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
</wsdl:types>
或者
<wsdl:types>
<xsd:schema targetNamespace="http://www.mysite.com/MyApp"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>
<xsd:simpleType name="MyEnum">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Item1" />
<xsd:enumeration value="Item2" />
<xsd:enumeration value="Item3" />
<xsd:enumeration value="SpecialItem" />
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
</wsdl:types>
I tried to look this up online, but all the WSDL examples seem to not really explain if I should mark things as basetype string in the WSDL or int...
Basically, I'm trying to make my WSDL so that I can represent an Enumeration. I have a C# Enum in mind already that I want to match it up to...
public enum MyEnum {
Item1 = 0,
Item2 = 1,
Item3 = 2,
SpecialItem = 99
}
I'm not sure how my WSDL should look... I figure it's one of two, but even then I'm not 100% sure...
<wsdl:types>
<xsd:schema targetNamespace="http://www.mysite.com/MyApp"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>
<xsd:simpleType name="MyEnum">
<xsd:restriction base="xsd:int">
<xsd:enumeration value="0" />
<xsd:enumeration value="1" />
<xsd:enumeration value="2" />
<xsd:enumeration value="99" />
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
</wsdl:types>
OR
<wsdl:types>
<xsd:schema targetNamespace="http://www.mysite.com/MyApp"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>
<xsd:simpleType name="MyEnum">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Item1" />
<xsd:enumeration value="Item2" />
<xsd:enumeration value="Item3" />
<xsd:enumeration value="SpecialItem" />
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
</wsdl:types>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
枚举最终看起来就像它们的字符串表示形式。因此,正确的 wsdl 会将枚举呈现为:
上面的内容将自动为您序列化/反序列化为 MyEnum 枚举类型。如果您将枚举表示为 xsd:int 那么您最终将不得不手动来回转换它们。
您可以像这样引用架构中的枚举定义:
Enumerations will end up looking like their string representations. So the correct wsdl will present the enums as:
The above will automatically serialize/deserialize to the MyEnum enumeration type for you. If you present the enums as xsd:int then you will end up having to convert them manually back and forth.
You can refer to the enumeration definition within your schema like so: