WSDL,枚举和C#:它仍然低迷 [英] WSDL, Enums and C#: It's still murky

查看:181
本文介绍了WSDL,枚举和C#:它仍然低迷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着在网上看这件事,但所有的WSDL例子似乎没有真正解释我是否应该标注事情在WSDL或者int ...



基类型的字符串

基本上,我试图让我的WSDL,这样我可以表示枚举。我有一个C#的枚举心中已经是我想匹配起来,以...

 公共枚举MyEnum {
项目1 = 0,
项目2 = 1,
项目3 = 2,
SpecialItem = 99
}

我不知道我的WSDL应该是什么样子......我想,这是两个之一,但即使如此,我不是100%肯定...

 < WSDL:类型> 
< XSD:架构的targetNamespace =htt​​p://www.mysite.com/MyApp
的xmlns:XSD =htt​​p://www.w3.org/2001/XMLSchema
>
< XSD:简单类型名称=MyEnum>
< XSD:限制基地=XSD:INT>
< XSD:枚举值=0/>
< XSD:枚举值=1/>
< XSD:枚举值=2/>
< XSD:枚举值=99/>
< / XSD:限制>
< / XSD:简单类型>
< / XSD:架构>
< / WSDL:类型>

 < WSDL:类型> 
< XSD:架构的targetNamespace =htt​​p://www.mysite.com/MyApp
的xmlns:XSD =htt​​p://www.w3.org/2001/XMLSchema
>
< XSD:简单类型名称=MyEnum>
< XSD:限制基地=XSD:字符串>
< XSD:枚举值=项目1/>
< XSD:枚举值=项目2/>
< XSD:枚举值=项目3/>
< XSD:枚举值=SpecialItem/>
< / XSD:限制>
< / XSD:简单类型>
< / XSD:架构>
< / WSDL:类型>


解决方案

枚举最终会看起来像它们的字符串表示。所以,正确的WSDL将呈现枚举为:

 < XS:简单类型名称=MyEnum> 
< XS:限制基地=XSD:字符串>
< XS:枚举值=项目1/>
< XS:枚举值=项目2/>
< XS:枚举值=项目3/>
< XS:枚举值=SpecialItem/>
< / XS:限制>
< / XS:简单类型>



以上会自动序列化/反序列化到MyEnum枚举类型适合你。如果您目前的枚举为XSD:整数,那么你最终将不得不将它们转换手动来回



您可以参考枚举的定义,像这样的架构中

 < XSD:复杂类型名称=1级> 
< XSD:序列>
< XSD:元素的minOccurs =1的maxOccurs =1NAME =MyEnumPropertyTYPE =MyEnum/>
< / XSD:序列>
< /为xsd:复杂类型>


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>

解决方案

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>

这篇关于WSDL,枚举和C#:它仍然低迷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆