加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

wsdl

发布时间:2020-12-16 06:11:29 所属栏目:百科 来源:网络整理
导读:wsdl wsdl(webservice description language),web服务描述语言,主要采用xml来描述网络服务和定位网络服务。 通俗地说,wsdl文档描述了webservice的如下3个方面: lWHAT:该web service包含“什么”操作; lHOW:该web service的操作应该“怎么”调用; lW

wsdl

wsdl(webservice description language),web服务描述语言,主要采用xml来描述网络服务和定位网络服务。 通俗地说,wsdl文档描述了webservice的如下3个方面:

lWHAT:该web service包含“什么”操作;

lHOW:该web service的操作应该“怎么”调用;

lWHERE:该web service的服务地址;

wsdl 文档将web服务定义为服务访问点或端口的集合。在 wsdl 中,由于服务访问点和消息的抽象定义已从具体的服务部署或数据格式绑定中分离出来,因此可以对抽象定义进行再次使用:消息,指对交换数据的抽象描述;而端口类型,指操作的抽象集合。用于特定端口类型的具体协议和数据格式规范构成了可以再次使用的绑定。将web访问地址与可再次使用的绑定相关联,可以定义一个端口,而端口的集合则定义为服务。

wsdl文档在web服务的定义中主要使用types、message、operation、portType、binding、port、service等子元素来描述webservice,一个wsdl文档的主要结构如下:

<definitions> 
<types> 
definition of types........ 
</types> 
<message> 
definition of a message.... 
</message> 
<portType> 
definition of a port....... 
</portType> 
<binding> 
definition of a binding.... 
</binding> 
<service> 
definition of a service.... 
</service> 
 
 
</definitions>

ltypes元素定义web service使用的数据类型;

lmessage元素定义一个操作的数据元素(引用types中的数据类型),可以把一个消息当作传统编程语言中一个函数的所有参数或返回值;

loperation 一个operation描述了一个抽象的方法,一般单个operation描述了一个访问入口的请求、响应消息对(input、output);

lportType 所有operation的集合,可以把portType看作传统编程语言中的函数库,接口等;

lbinding 特定端口类型的具体协议和数据格式规范的绑定;

lport 定义协议、数据格式绑定与具体web访问地址组合的单个服务访问点;一个service往往会包含多个服务访问入口,而每个入口都会使用一个port来描述;

lservice相关服务点的集合。

总体来说,我们可以把type看作是参数类型;message是一个具体的参数(参数名+参数类型)或返回值;operation是一个函数,需要为每个函数指定参数和返回值;portType是函数库;binding指明消息所使用的协议等。具体的案例如下:

<?xml version="1.0" encoding="UTF-8"standalone="no"?>

<wsdl:definitions

xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"

xmlns:tns="http://www.ssl.com/"

xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"

xmlns:xsd="http://www.w3.org/2001/XMLSchema"

name="ServiceImplService"targetNamespace="http://www.ssl.com/">

<!-- 定义数据 -->

<wsdl:types>

<xsd:schema targetNamespace="http://www.ssl.com/">

<xsd:element name="add"type="tns:add"/>

<xsd:element name="addResponse"type="tns:addResponse"/>

<xsd:element name="licenseInfo"type="xsd:string"/>

<xsd:complexType name="add">

<xsd:sequence>

<xsd:element name="a"type="xsd:int"/>

<xsd:element name="b"type="xsd:int"/>

</xsd:sequence>

</xsd:complexType>

<xsd:complexType name="addResponse">

<xsd:sequence>

<xsd:element name="addResult"type="xsd:int"/>

</xsd:sequence>

</xsd:complexType>

</xsd:schema>

</wsdl:types>

<!-- 定义消息,一个函数一般需要两个消息,一个用于传输参数,一个用于接收参数 -->

<wsdl:message name="add">

<wsdl:part name="add"element="tns:add"/>

</wsdl:message>

<wsdl:message name="addResponse">

<wsdl:part name="addResponse"element="tns:addResponse"/>

</wsdl:message>

<wsdl:message name="licenseInfo">

<wsdl:part name="licenseInfo"element="tns:licenseInfo"/>

</wsdl:message>

<!--指定函数,以及所需要的参数 -->

<wsdl:portType name="service">

<wsdl:operation name="add">

<wsdl:input message="tns:add"/>

<wsdl:output message="tns:addResponse"/>

</wsdl:operation>

</wsdl:portType>

<!-- 将消息和协议绑定 -->

<wsdl:binding name="serviceSOAP"type="tns:service">

<soap:binding style="document"transport="http://schemas.xmlsoap.org/soap/http"/>

<wsdl:operation name="add">

<wsdl:input>

<soap:body use="literal"/>

<soap:header use="literal"part="licenseInfo" message="tns:licenseInfo"/>

</wsdl:input>

<wsdl:output>

<soap:body use="literal"/>

</wsdl:output>

</wsdl:operation>

</wsdl:binding>

<!-- web service名称和地址等 -->

<wsdl:service name="ServiceImplService">

<wsdl:port binding="tns:serviceSOAP"name="ServiceImplPort">

<soap:address location="http://127.0.0.1:8080/service"/>

</wsdl:port>

</wsdl:service>

</wsdl:definitions>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读