博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WSDL详解
阅读量:4069 次
发布时间:2019-05-25

本文共 13931 字,大约阅读时间需要 46 分钟。

<div id="veryContent" class="real_blog" style="text-indent: 2em; height: auto !important;">
<table id="blogContentTable" style="width: 100%;" border="0" cellspacing="0" cellpadding="0"><tbody><tr>
<td style="" valign="top">
<div id="blogContainer" style="height: 100%; overflow: hidden;">
<img id="paperPicArea0" style="display: none;" src="ac/b.gif" alt=""><div id="paperTitleArea"></div>
<img id="paperPicArea" style="display: none;" src="ac/b.gif" alt=""><div id="blogDetailDiv" style="font-size: 16px;">WSDL (Web Services Description Language,Web服务描述语言)是一种XML Application,他将Web服务描述定义为一组服务访问点,客户端可以通过这些服务访问点对包含面向文档信息或面向过程调用的服务进行访问(类似远程过程调用)。WSDL首先对访问的操作和访问时使用的请求/响应消息进行抽象描述,然后将其绑定到具体的传输协议和消息格式上以最终定义具体部署的服务访问点。相关的具体部署的服务访问点通过组合就成为抽象的Web服务。 本文将详细讲解WSDL文档的结构,并分析每个元素的作用。 一:WSDL定义 <br>WSDL是一个用于精确描述Web服务的文档,WSDL文档是一个遵循WSDL XML模式的XML文档。WSDL 文档将Web服务定义为服务访问点或端口的集合。在 WSDL 中,由于服务访问点和消息的抽象定义已从具体的服务部署或数据格式绑定中分离出来,因此可以对抽象定义进行再次使用:消息,指对交换数据的抽象描述;而端口类型,指操作的抽象集合。用于特定端口类型的具体协议和数据格式规范构成了可以再次使用的绑定。将Web访问地址与可再次使用的绑定相关联,可以定义一个端口,而端口的集合则定义为服务。 <br> 一个WSDL文档通常包含7个重要的元素,即types、import、message、portType、operation、binding、service元素。这些元素嵌套在definitions元素中,definitions是WSDL文档的根元素。文章的下一部分将会详细介绍WSDL的基本结构。 <br>二:WSDL的基本结构--概述 <br>如第一部分最后描述的那样,一个基本的WSDL文档包含7个重要的元素。下面将分别介绍这几个元素以及他们的作用。 <br>WSDL 文档在Web服务的定义中使用下列元素: <br><ul style="">
<li style="margin: 25px;">
<span style="font-weight: bold;">Types</span> - 数据类型定义的容器,它使用某种类型系统(一般地使用XML Schema中的类型系统)。 </li>
<li style="margin: 25px;">
<span style="font-weight: bold;">Message</span> - 通信消息的数据结构的抽象类型化定义。使用Types所定义的类型来定义整个消息的数据结构。 </li>
<li style="margin: 25px;">
<span style="font-weight: bold;">Operation</span> - 对服务中所支持的操作的抽象描述,一般单个Operation描述了一个访问入口的请求/响应消息对。 </li>
<li style="margin: 25px;">
<span style="font-weight: bold;">PortType</span> - 对于某个访问入口点类型所支持的操作的抽象集合,这些操作可以由一个或多个服务访问点来支持。 </li>
<li style="margin: 25px;">
<span style="font-weight: bold;">Binding</span> - 特定端口类型的具体协议和数据格式规范的绑定。 </li>
<li style="margin: 25px;">
<span style="font-weight: bold;">Port</span> - 定义为协议/数据格式绑定与具体Web访问地址组合的单个服务访问点。 </li>
<li style="margin: 25px;">
<span style="font-weight: bold;">Service</span>- 相关服务访问点的集合。 </li>
</ul>
可以参考下图来理解一下WSDL的文档结构图:<a href="https://p-blog.csdn.net/images/p_blog_csdn_net/juxtapose/wsdl-01.gif" target="_blank"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px;" src="https://p-blog.csdn.net/images/p_blog_csdn_net/juxtapose/wsdl-01.gif" alt=""></a> <br>WSDL的xml schema可以参照如下网址:<a href="http://schemas.xmlsoap.org/wsdl/" target="_blank"><span style="line-height: 1.8em; color: #006699;">http://schemas.xmlsoap.org/wsdl/</span></a> <br>三:WSDL的基本结构--详述 <br>本节将通过一个例子详细描述WSDL文档每个元素的作用。下面一个例子是一个简单的WSDL文档的内容,该文档的产生可以参见我的另外一篇文章:<a href="http://blog.csdn.net/juxtapose/archive/2007/09/10/1779849.aspx" target="_blank"><span style="line-height: 1.8em; color: #006699;">xfire开发实例--HelloWorld篇</span></a> (<a href="http://blog.csdn.net/juxtapose/archive/2007/09/10/1779849.aspx" target="_blank"><span style="line-height: 1.8em; color: #006699;">http://blog.csdn.net/juxtapose/archive/2007/09/10/1779849.aspx</span></a>)。 <br>一个简单的Web Service的WSDL文档,该服务支持名为sayHello的唯一操作,该操作通过在http上运行SOAP协议来实现的。该请求接受一个字符串name,经过处理后返回一个简单的字符串。文档如下: <br><?xml version="1.0" encoding="UTF-8" ?> <br><wsdl:definitions <br>targetNamespace="http://com.liuxiang.xfireDemo/HelloService" <br>xmlns:tns="http://com.liuxiang.xfireDemo/HelloService" <br>xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" <br>xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" <br>xmlns:xsd="http://www.w3.org/2001/XMLSchema" <br>xmlns:soapenc11="http://schemas.xmlsoap.org/soap/encoding/" <br>xmlns:soapenc12="http://www.w3.org/2003/05/soap-encoding" <br>xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/" <br>xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"> <br><wsdl:types> <br><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" <br>attributeFormDefault="qualified" elementFormDefault="qualified" <br>targetNamespace="http://com.liuxiang.xfireDemo/HelloService"> <br><xsd:element name="sayHello"> <br><xsd:complexType> <br><xsd:sequence> <br><xsd:element maxOccurs="1" minOccurs="1" <br>name="name" nillable="true" type="xsd:string" /> <br></xsd:sequence> <br></xsd:complexType> <br></xsd:element> <br><xsd:element name="sayHelloResponse"> <br><xsd:complexType> <br><xsd:sequence> <br><xsd:element maxOccurs="1" minOccurs="1" <br>name="out" nillable="true" type="xsd:string" /> <br></xsd:sequence> <br></xsd:complexType> <br></xsd:element> <br></xsd:schema> <br></wsdl:types> <br><wsdl:message name="sayHelloResponse"> <br><wsdl:part name="parameters" element="tns:sayHelloResponse" /> <br></wsdl:message> <br><wsdl:message name="sayHelloRequest"> <br><wsdl:part name="parameters" element="tns:sayHello" /> <br></wsdl:message> <br><wsdl:portType name="HelloServicePortType"> <br><wsdl:operation name="sayHello"> <br><wsdl:input name="sayHelloRequest" <br>message="tns:sayHelloRequest" /> <br><wsdl:output name="sayHelloResponse" <br>message="tns:sayHelloResponse" /> <br></wsdl:operation> <br></wsdl:portType> <br><wsdl:binding name="HelloServiceHttpBinding" <br>type="tns:HelloServicePortType"> <br><wsdlsoap:binding style="document" <br>transport="http://schemas.xmlsoap.org/soap/http" /> <br><wsdl:operation name="sayHello"> <br><wsdlsoap:operation soapAction="" /> <br><wsdl:input name="sayHelloRequest"> <br><wsdlsoap:body use="literal" /> <br></wsdl:input> <br><wsdl:output name="sayHelloResponse"> <br><wsdlsoap:body use="literal" /> <br></wsdl:output> <br></wsdl:operation> <br></wsdl:binding> <br><wsdl:service name="HelloService"> <br><wsdl:port name="HelloServiceHttpPort" <br>binding="tns:HelloServiceHttpBinding"> <br><wsdlsoap:address <br>location="http://localhost:8080/xfire/services/HelloService" /> <br></wsdl:port> <br></wsdl:service> <br></wsdl:definitions> <br>? types元素使用XML模式语言声明在WSDL文档中的其他位置使用的复杂数据类型与元素; <br>? import元素类似于XML模式文档中的import元素,用于从其他WSDL文档中导入WSDL定义; <br>? message元素使用在WSDL文档的type元素中定义或在import元素引用的外部WSDL文档中定义的XML模式的内置类型、复杂类型或元素描述了消息的有效负载; <br>? portType元素和operation元素描述了Web服务的接口并定义了他的方法。portType元素和operation元素类似于java接口和接口中定义的方法声明。operation元素使用一个或者多个message类型来定义他的输入和输出的有效负载; <br>? Binding元素将portType元素和operation元素赋给一个特殊的协议和编码样式; <br>? service元素负责将Internet地址赋给一个具体的绑定; <br>1、definitions元素 <br>所有的WSDL文档的根元素均是definitions元素。该元素封装了整个文档,同时通过其name提供了一个WSDL文档。除了提供一个命名空间外,该元素没有其他作用,故不作详细描述。 <br>下面的代码是一个definitions元素的结构: <br><wsdl:definitions <br>targetNamespace="http://com.liuxiang.xfireDemo/HelloService" <br>xmlns:tns="http://com.liuxiang.xfireDemo/HelloService" <br>xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" <br>xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" <br>xmlns:xsd="http://www.w3.org/2001/XMLSchema" <br>xmlns:soapenc11="http://schemas.xmlsoap.org/soap/encoding/" <br>xmlns:soapenc12="http://www.w3.org/2003/05/soap-encoding" <br>xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/" <br>xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"> <br></wsdl:definitions> <br>2、types元素 <br>WSDL采用了W3C XML模式内置类型作为其基本类型系统。types元素用作一个容器,用于定义XML模式内置类型中没有描述的各种数据类型。当声明消息部分的有效负载时,消息定义使用了在types元素中定义的数据类型和元素。在本文的WSDL文档中的types定义: <br><br><wsdl:types> <br><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" <br>attributeFormDefault="qualified" elementFormDefault="qualified" <br>targetNamespace="http://com.liuxiang.xfireDemo/HelloService"> <br><xsd:element name="sayHello"> <br><xsd:complexType> <br><xsd:sequence> <br><xsd:element maxOccurs="1" minOccurs="1" <br>name="name" nillable="true" type="xsd:string" /> <br></xsd:sequence> <br></xsd:complexType> <br></xsd:element> <br><xsd:element name="sayHelloResponse"> <br><xsd:complexType> <br><xsd:sequence> <br><xsd:element maxOccurs="1" minOccurs="1" <br>name="out" nillable="true" type="xsd:string" /> <br></xsd:sequence> <br></xsd:complexType> <br></xsd:element> <br></xsd:schema> <br></wsdl:types> <br>上面是数据定义部分,该部分定义了两个元素,一个是sayHello,一个是sayHelloResponse: <br>sayHello:定义了一个复杂类型,仅仅包含一个简单的字符串,将来用来描述操作的参入传入部分; <br>sayHelloResponse:定义了一个复杂类型,仅仅包含一个简单的字符串,将来用来描述操作的返回值; <br>3、import元素 <br>import元素使得可以在当前的WSDL文档中使用其他WSDL文档中指定的命名空间中的定义元素。本例子中没有使用import元素。通常在用户希望模块化WSDL文档的时候,该功能是非常有效果的。 <br>import的格式如下: <br><a href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" target="_blank"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px;" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt=""></a><wsdl:import namespace="http://xxx.xxx.xxx/xxx/xxx" location="http://xxx.xxx.xxx/xxx/xxx.wsdl"/> <br>必须有namespace属性和location属性: <br>namespace属性:值必须与正导入的WSDL文档中声明的targetNamespace相匹配; <br>location属性:必须指向一个实际的WSDL文档,并且该文档不能为空。 <br>4、message元素 <br>message元素描述了Web服务使用消息的有效负载。message元素可以描述输出或者接受消息的有效负载;还可以描述SOAP文件头和错误detail元素的内容。定义message元素的方式取决于使用RPC样式还是文档样式的消息传递。在本文中的message元素的定义,本文档使用了采用文档样式的消息传递: <br><wsdl:message name="sayHelloResponse"> <br><wsdl:part name="parameters" element="tns:sayHelloResponse" /> <br></wsdl:message> <br><wsdl:message name="sayHelloRequest"> <br><wsdl:part name="parameters" element="tns:sayHello" /> <br></wsdl:message> <br>该部分是消息格式的抽象定义:定义了两个消息sayHelloResponse和sayHelloRequest: <br>sayHelloRequest:sayHello操作的请求消息格式,由一个消息片断组成,名字为parameters,元素是我们前面定义的types中的元素; <br>sayHelloResponse:sayHello操作的响应消息格式,由一个消息片断组成,名字为parameters,元素是我们前面定义的types中的元素; <br>如果采用RPC样式的消息传递,只需要将文档中的element元素应以修改为type即可。 <br>5、portType元素 <br>portType元素定义了Web服务的抽象接口。该接口有点类似Java的接口,都是定义了一个抽象类型和方法,没有定义实现。在WSDL中,portType元素是由binding和service元素来实现的,这两个元素用来说明Web服务实现使用的Internet协议、编码方案以及Internet地址。 <br>一个portType中可以定义多个operation,一个operation可以看作是一个方法,本文中WSDL文档的定义: <br><a href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" target="_blank"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px;" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt=""></a><wsdl:portType name="HelloServicePortType"> <br><a href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" target="_blank"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px;" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt=""></a><wsdl:operation name="sayHello"> <br><a href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" target="_blank"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px;" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt=""></a><wsdl:input name="sayHelloRequest" <br><a href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" target="_blank"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px;" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt=""></a>message="tns:sayHelloRequest" /> <br><a href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" target="_blank"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px;" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt=""></a><wsdl:output name="sayHelloResponse" <br><a href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" target="_blank"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px;" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt=""></a>message="tns:sayHelloResponse" /> <br><a href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" target="_blank"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px;" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt=""></a></wsdl:operation> <br><a href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" target="_blank"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px;" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt=""></a></wsdl:portType> <br>portType定义了服务的调用模式的类型,这里包含一个操作sayHello方法,同时包含input和output表明该操作是一个请求/响应模式,请求消息是前面定义的sayHelloRequest,响应消息是前面定义的sayHelloResponse。input表示传递到Web服务的有效负载,output消息表示传递给客户的有效负载。 <br>6、binding <br>binding元素将一个抽象portType映射到一组具体协议(SOAO和HTTP)、消息传递样式、编码样式。通常binding元素与协议专有的元素和在一起使用,本文中的例子: <br><wsdl:binding name="HelloServiceHttpBinding" <br>type="tns:HelloServicePortType"> <br><wsdlsoap:binding style="document" <br>transport="http://schemas.xmlsoap.org/soap/http" /> <br><wsdl:operation name="sayHello"> <br><wsdlsoap:operation soapAction="" /> <br><wsdl:input name="sayHelloRequest"> <br><wsdlsoap:body use="literal" /> <br></wsdl:input> <br><wsdl:output name="sayHelloResponse"> <br><wsdlsoap:body use="literal" /> <br></wsdl:output> <br></wsdl:operation> <br></wsdl:binding> <br>这部分将服务访问点的抽象定义与SOAP HTTP绑定,描述如何通过SOAP/HTTP来访问按照前面描述的访问入口点类型部署的访问入口。其中规定了在具体SOAP调用时,应当使用的soapAction是""。 <br>具体的使用需要参考特定协议定义的元素。 <br>7、service元素和port元素 <br>service元素包含一个或者多个port元素,其中每个port元素表示一个不同的Web服务。port元素将URL赋给一个特定的binding,甚至可以使两个或者多个port元素将不同的URL赋值给相同的binding。文档中的例子: <br><wsdl:service name="HelloService"> <br><wsdl:port name="HelloServiceHttpPort" <br>binding="tns:HelloServiceHttpBinding"> <br><wsdlsoap:address <br>location="http://localhost:8080/xfire/services/HelloService" /> <br></wsdl:port> <br></wsdl:service> <br>这部分是具体的Web服务的定义,在这个名为HelloService的Web服务中,提供了一个服务访问入口,访问地址是<a href="http://localhost:8080/xfire/services/HelloService" target="_blank"><span style="line-height: 1.8em; color: #006699;">http://localhost:8080/xfire/services/HelloService</span></a>,使用的消息模式是由前面的binding所定义的。 <!--v:3.2-->
</div>
</div>
</td>
</tr></tbody></table>
</div>
你可能感兴趣的文章
Windows 7下硬盘安装CentOS6.4的解决方法
查看>>
JSP不支持EL表达式的解决方案
查看>>
Struts2类型转换器
查看>>
struts2 使用注解、反射、拦截器实现基于方法的权限控制
查看>>
maven 架设 struts2 注解方式 权限控制
查看>>
struts2之多个文件上传
查看>>
struts2之单个文件上传
查看>>
struts2自定义拦截器 模拟session超时的处理
查看>>
面试技巧
查看>>
struts2之防止表单重复提交
查看>>
人不成熟的几大特征
查看>>
《礼仪73》、《处事22计》、《心态24条》、《伤心50句》、《学会长大20》
查看>>
人人都会变老
查看>>
oracle connect by用法
查看>>
Oracle 树操作(select…start with…connect by…prior)
查看>>
maven struts2中,使用ModelDriven
查看>>
通过web.xml传递初始参数
查看>>
过滤器与拦截器
查看>>
maven 下成功搭建hibernate
查看>>
maven hibernate 实现对mysql简单的CRUD操作
查看>>