WSDL、Enums 和 C#:仍然很模糊

发布于 2024-09-17 09:56:40 字数 1562 浏览 3 评论 0原文

我试图在网上查找这一点,但所有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三岁铭 2024-09-24 09:56:40

枚举最终看起来就像它们的字符串表示形式。因此,正确的 wsdl 会将枚举呈现为:

<xs:simpleType name="MyEnum">
    <xs:restriction base="xsd:string">
      <xs:enumeration value="Item1" />
      <xs:enumeration value="Item2" />
      <xs:enumeration value="Item3" />
      <xs:enumeration value="SpecialItem" />
    </xs:restriction>
  </xs:simpleType>

上面的内容将自动为您序列化/反序列化为 MyEnum 枚举类型。如果您将枚举表示为 xsd:int 那么您最终将不得不手动来回转换它们。

您可以像这样引用架构中的枚举定义:

<xsd:complexType name="Class1">
    <xsd:sequence>
      <xsd:element minOccurs="1" maxOccurs="1" name="MyEnumProperty" type="MyEnum" />
    </xsd:sequence>
  </xsd:complexType>

Enumerations will end up looking like their string representations. So the correct wsdl will present the enums as:

<xs:simpleType name="MyEnum">
    <xs:restriction base="xsd:string">
      <xs:enumeration value="Item1" />
      <xs:enumeration value="Item2" />
      <xs:enumeration value="Item3" />
      <xs:enumeration value="SpecialItem" />
    </xs:restriction>
  </xs:simpleType>

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:

<xsd:complexType name="Class1">
    <xsd:sequence>
      <xsd:element minOccurs="1" maxOccurs="1" name="MyEnumProperty" type="MyEnum" />
    </xsd:sequence>
  </xsd:complexType>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文