Web Service描述语言 WSDL 详解(5)

数组

  XSD提供<list>结构来声明一个数组,元素之间有空格界定。不过SOAP不是使用XSD来编码数组的,它定义了自己的数组类型--"SOAP-ENC: Array"。下列的例子揭示了从这一类型派生出一位整数数组的方法:

<xsd:complexType name="ArrayOfInt">
<xsd:complexContent>
 <xsd:restriction base="soapenc:Array">
  <attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:int[]"/>
 </xsd:restriction>
</xsd:complexContent>
</xsd:complexType>

  新的complex类型从soapenc:array限制派生。然后又声明了complex类型的一个属性。引用"soapenc:arrayType"实际上是这样完成的:

<xsd:attribute name="arrayType" type="xsd:string"/>

  wsdl:arrayType属性值决定了数组每个成员的类型。数组的成员也可以是Complex类型。:

<xsd:complexType name="ArrayOfPERSON">
<xsd:complexContent>
<xsd:restriction base="soapenc:Array">
<attribute ref="soapenc:arrayType"
wsdl:arrayType="typens:PERSON[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>

  WSDL要求数组的类型由"ArrayOf"和每个数组元素的类型串联而成。很显然,顾名思义,"ArrayOfPERSON"是PERSON结构的数组。下面我将使用ArrayOfPERSON来声明一个<message>,并加入不止一个PERSON:

<?xml version="1.0" encoding="UTF-8" ?>
<definitions … >
<types>
<schema targetNamespace="someNamespace"
xmlns:typens="someNamespace" >
<xsd:complexType name="PERSON">
 <xsd:sequence>
  <xsd:element name="firstName" type="xsd:string"/>
  <xsd:element name="lastName" type="xsd:string"/>
  <xsd:element name="ageInYears" type="xsd:int"/>
  <xsd:element name="weightInLbs" type="xsd:float"/>
  <xsd:element name="heightInInches" type="xsd:float"/>
 </xsd:sequence>
</xsd:complexType>
<xsd:complexType name="ArrayOfPERSON">
<xsd:complexContent>
<xsd:restriction base="soapenc:Array">
<attribute ref="soapenc:arrayType"
wsdl:arrayType="typens:PERSON[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
</schema>
</types>

<message name="addPersons">
 <part name="person" type="typens:ArrayOfPERSON"/>
</message>

<message name="addPersonResponse">
 <part name="result" type="xsd:int"/>
</message>

</definitions>

<portType>和<operation>元素

  PortType定义了一些抽象的操作。PortType中的operation元素定义了调用PortType中所有方法的语法,每一个operation元素声明了方法的名称、参数(使用<message>元素)和各自的类型(<part>元素要在所有<message>中声明)。

  在一篇WSDL文档中可以有几个<PortType>元素,每一个都和一些相关操作放在一起,就和COM和一组操作的接口相似。

  在<operation>元素中,可能会有至多一个<input>元素,一个<output>元素,以及一个<fault>元素。三个元素各有一个名字和一个消息属性。

  <input>, <output>, <fault>元素属性的名字有何含义呢?它们可以用来区别两个同名操作(重载)。例如,看下面两个C函数:

void foo(int arg);
void foo(string arg);

  这种重载在WSDL中可以这样表示:

<?xml version="1.0" encoding="UTF-8" ?>
<definitions name="fooDescription"
 targetNamespace="http://tempuri.org/wsdl/"
 xmlns:wsdlns="http://tempuri.org/wsdl/"
 xmlns:typens="http://tempuri.org/xsd"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
 xmlns:stk="http://schemas.microsoft.com/soap-toolkit/wsdl-
 extension"
 xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<schema targetNamespace="http://tempuri.org/xsd"
 xmlns="http://www.w3.org/2001/XMLSchema"
 xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
 xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
 elementFormDefault="qualified" >
</schema>
</types>

<message name="foo1">
 <part name="arg" type="xsd:int"/>
</message>

<message name="foo2">
 <part name="arg" type="xsd:string"/>
</message>

<portType name="fooSamplePortType">
<operation name="foo" parameterOrder="arg " >
 <input name="foo1" message="wsdlns:foo1"/>
</operation>
<operation name="foo" parameterOrder="arg " >
 <input name="foo2" message="wsdlns:foo2"/>
</operation>
</portType>

<binding name="fooSampleBinding" type="wsdlns:fooSamplePortType">
<stk:binding preferredEncoding="UTF-8" />
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="foo">
<soap:operation soapAction="http://tempuri.org/action/foo1"/>
 <input name="foo1">
  <soap:body use="encoded" namespace="http://tempuri.org/message/"
    encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
 </input>
</operation>
<operation name="foo">
<soap:operation soapAction="http://tempuri.org/action/foo2"/>
<input name="foo2">
<soap:body use="encoded"
   namespace="http://tempuri.org/message/"
   encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
/>
</input>
</operation>
</binding>

<service name="FOOService">
<port name="fooSamplePort" binding="fooSampleBinding">
<soap:address
  location="http://carlos:8080/fooService/foo.asp"/>
</port>
</service>
</definitions>

  到目前为止,还没有一种SOAP的实现支持重载。这对基于JAVA的客户端十分重要,因为JAVA服务器使用的接口用到JAVA的重载特性。而对基于COM的客户端,就不那么重要,因为COM是不支持重载的。

阅读终点,创作起航,您可以撰写心得或摘录文章要点写篇博文。去创作
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: WSDL (Web Services Description Language) 是一种用于描述 Web 服务的语言。它使用 XML 格式来描述 Web 服务和如何访问它们。 Web 服务体系结构中的 WSDL 实现可以提供以下信息: - 服务所在的位置 (URL) - 服务所提供的功能 (例如,查询数据库、检查天气预报等) - 调用服务所需的输入参数 - 服务返回的输出结果 通常,WSDL 文件会包含一个描述 Web 服务的接口的 XML 文档,以及如何访问该接口的详细信息。有了 WSDL 文件,客户端程序就可以使用特定的工具生成代码来调用 Web 服务。 ### 回答2: Web服务体系结构是一种基于网络的架构,它允许不同平台和应用程序之间进行通信和交互。其中,WSDLWeb Services Description Language)是一种用于描述Web服务的XML格式语言WSDL可以被用来描述一个Web服务的功能、输入输出等细节。一般来说,一个简单的Web服务体系结构的WSDL实现会包含以下几个部分: 1. 服务接口(Service Interface):描述Web服务可提供的功能和操作,包括输入参数、输出参数和返回类型等。例如,一个简单的Web服务可能提供一个计算两个数相加的功能。 2. 绑定(Binding):将服务接口与具体的协议和传输机制绑定在一起。例如,绑定可以指定该Web服务使用SOAP协议进行通信,并通过HTTP协议进行传输。 3. 服务地址(Service Address):指定Web服务的网络地址,客户端可以通过该地址访问并调用服务。例如,一个Web服务的地址可以是一个URL(Uniform Resource Locator)。 4. 数据类型(Data Types):定义服务接口中所使用的数据类型。例如,对于前述计算两个数相加的功能,可能需要定义整数类型作为输入参数和返回值的数据类型。 通过这些部分的描述WSDL实现可以为Web服务提供者和消费者提供一个统一的规范和约定,使得它们之间能够理解和相互协作。同时,WSDL实现还可以被用来生成客户端代码,使得客户端可以轻松地调用Web服务。 总而言之,WSDL实现是描述Web服务体系结构的一种XML格式语言,它定义了服务接口、绑定、服务地址和数据类型等方面的细节。通过WSDL实现,Web服务的提供者和消费者可以共同遵守一套标准和约定,实现不同平台和应用程序之间的互操作性。 ### 回答3: Web服务描述语言(WSDL)是一种用于描述和定义Web服务体系结构的XML语言。它允许开发人员描述一个Web服务的接口、访问地址、操作和消息格式等细节。以下是一个简单的描述Web服务体系结构的WSDL实现: ``` <?xml version="1.0" encoding="UTF-8"?> <wsdl:definitions name="MyWebService" targetNamespace="http://www.example.com/webservice" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.example.com/webservice" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <wsdl:types> <xsd:schema targetNamespace="http://www.example.com/webservice"> <xsd:element name="GetEmployeeRequest"> <xsd:complexType> <xsd:sequence> <xsd:element name="EmployeeID" type="xsd:int"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="GetEmployeeResponse"> <xsd:complexType> <xsd:sequence> <xsd:element name="EmployeeName" type="xsd:string"/> <xsd:element name="EmployeeEmail" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> </wsdl:types> <wsdl:message name="GetEmployeeRequestMessage"> <wsdl:part name="parameters" element="tns:GetEmployeeRequest"/> </wsdl:message> <wsdl:message name="GetEmployeeResponseMessage"> <wsdl:part name="parameters" element="tns:GetEmployeeResponse"/> </wsdl:message> <wsdl:portType name="MyWebServicePortType"> <wsdl:operation name="GetEmployee"> <wsdl:input message="tns:GetEmployeeRequestMessage"/> <wsdl:output message="tns:GetEmployeeResponseMessage"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name="MyWebServiceSoapBinding" type="tns:MyWebServicePortType"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/> <wsdl:operation name="GetEmployee"> <soap:operation soapAction="http://www.example.com/webservice/GetEmployee" style="rpc"/> <wsdl:input> <soap:body use="literal" namespace="http://www.example.com/webservice"/> </wsdl:input> <wsdl:output> <soap:body use="literal" namespace="http://www.example.com/webservice"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="MyWebService"> <wsdl:port name="MyWebServicePort" binding="tns:MyWebServiceSoapBinding"> <soap:address location="http://www.example.com/webservice"/> </wsdl:port> </wsdl:service> </wsdl:definitions> ``` 在上述WSDL实现中,我们定义了一个名为"MyWebService"的Web服务,它包含一个名为"GetEmployee"的操作。该操作接收一个名为"EmployeeID"的整数输入参数,并返回一个包含"EmployeeName"和"EmployeeEmail"的响应。WSDL还定义了消息、端口类型、绑定和服务等相关细节。 这段WSDL实现描述Web服务的接口、访问地址和操作等信息,使得服务的使用者能够了解如何与该服务进行交互,并正确构造请求和解析响应。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

abedon

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值