C# 如何在 WSDL 中定义一组自定义类型?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2293873/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 01:10:27  来源:igfitidea点击:

How do I define an array of custom types in WSDL?

c#pythonweb-servicessoapwsdl

提问by MStodd

I'm very new to WSDL, but what I'm trying to do is very simple. I have gotten a web service working with python's ZSI library, but am stuck defining a service which returns an array of a custom type.

我对 WSDL 很陌生,但我想要做的很简单。我得到了一个使用 python 的 ZSI 库的 web 服务,但是我坚持定义一个返回自定义类型数组的服务。

In my WSDL I have the following:

在我的 WSDL 中,我有以下内容:

<xsd:element name="ArtPiece">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="title" type="xsd:string" />
        <xsd:element name="year" type="xsd:string" />
        <xsd:element name="imageId" type="xsd:int"  minOccurs="0" />
        <xsd:element name="image" type="xsd:base64Binary"  minOccurs="0" />
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>

If I try to add another element like ArtPieceArray that's defined by having an unlimited number of ArtPiece types, that seems to be invalid.

如果我尝试添加另一个元素,例如通过具有无限数量的 ArtPiece 类型定义的 ArtPieceArray,这似乎是无效的。

If, when I'm defining my message, I try to use ArtPiece[], that also seems to be invalid.

如果我在定义消息时尝试使用 ArtPiece[],那似乎也是无效的。

I'm using ZSI for the web service, and C# for the client. The client web service code is generated by wsdl.exe

我在 Web 服务中使用 ZSI,在客户端使用 C#。客户端 Web 服务代码由 wsdl.exe 生成

Any suggestions?

有什么建议?

采纳答案by Darin Dimitrov

<xs:schema elementFormDefault="qualified" 
           targetNamespace="http://schemas.datacontract.org/2004/07/Foo" 
           xmlns:xs="http://www.w3.org/2001/XMLSchema" 
           xmlns:tns="http://schemas.datacontract.org/2004/07/Foo">
    <xs:complexType name="ArtPiece">
        <xs:sequence>
            <xs:element minOccurs="0" name="image" nillable="true" type="xs:base64Binary"/>
            <xs:element minOccurs="0" name="imageId" type="xs:int"/>
            <xs:element minOccurs="0" name="title" nillable="true" type="xs:string"/>
            <xs:element minOccurs="0" name="year" nillable="true" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>

    <xs:element name="ArtPiece" nillable="true" type="tns:ArtPiece"/>

    <xs:complexType name="ArrayOfArtPiece">
        <xs:sequence>
            <xs:element minOccurs="0" maxOccurs="unbounded" name="ArtPiece" nillable="true" type="tns:ArtPiece"/>
        </xs:sequence>
    </xs:complexType>

    <xs:element name="ArrayOfArtPiece" nillable="true" type="tns:ArrayOfArtPiece"/>
</xs:schema>