理解WSDL

WSDL是干什么的?
Web服务的定义语言.通过WSDL你可以告诉别人您能够提供什么服务,或者你能干什么. 首先,我提供一个WSDL的例子,这个例子源于Netbeans5.5的BPEL的贷款教程。
WSDL例子
 
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <definitions targetNamespace="http://j2ee.netbeans.org/wsdl/LoanRequestor"  
  3.     xmlns="http://schemas.xmlsoap.org/wsdl/"  
  4.     xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"  
  5.     xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"  
  6.     xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="LoanRequestor" xmlns:plink="http://schemas.xmlsoap.org/ws/2004/03/partner-link/" xmlns:tns="http://j2ee.netbeans.org/wsdl/LoanRequestor" xmlns:ns="http://xml.netbeans.org/schema/LoanRequestor">  
  7.     <types>  
  8.         <xsd:schema targetNamespace="http://j2ee.netbeans.org/wsdl/LoanRequestor">  
  9.             <xsd:import namespace="http://xml.netbeans.org/schema/LoanRequestor" schemaLocation="LoanRequestor.xsd"/>  
  10.         </xsd:schema>  
  11.     </types>  
  12.     <message name="LoanRequestorOperationRequest">  
  13.         <part name="requestLoanMessage" element="ns:pa"/>  
  14.     </message>  
  15.     <message name="LoanRequestorOperationReply">  
  16.         <part name="responsePart" element="ns:par"/>  
  17.     </message>  
  18.     <portType name="LoanRequestorPortType">  
  19.         <operation name="LoanRequestorOperation">  
  20.             <input name="input1" message="tns:LoanRequestorOperationRequest"/>  
  21.             <output name="output1" message="tns:LoanRequestorOperationReply"/>  
  22.         </operation>  
  23.     </portType>  
  24.     <binding name="LoanRequestorBinding" type="tns:LoanRequestorPortType">  
  25.         <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>  
  26.         <operation name="LoanRequestorOperation">  
  27.             <soap:operation/>  
  28.             <input name="input1">  
  29.                 <soap:body use="literal"/>  
  30.             </input>  
  31.             <output name="output1">  
  32.                 <soap:body use="literal"/>  
  33.             </output>  
  34.         </operation>  
  35.     </binding>  
  36.     <service name="LoanRequestorService">  
  37.         <port name="LoanRequestorPort" binding="tns:LoanRequestorBinding">  
  38.             <soap:address location="http://localhost:18181/LoanRequestorService/LoanRequestorPort"/>  
  39.         </port>  
  40.     </service>  
  41.     <plink:partnerLinkType name="LoanRequestorPartner">  
  42.         <!-- partnerLinkType are automatically generated when a new portType is added. partnerLinkType are used by BPEL processes.   
  43. In a BPEL process, a partner link represents the interaction between the BPEL process and a partner service.Each partner link is associated with a partner link type.  
  44. A partner link type characterizes the conversational relationship between two services.The partner link type can have one or two roles.-->  
  45.         <plink:role name="LoanRequestorPortTypeRole" portType="tns:LoanRequestorPortType"/>  
  46.     </plink:partnerLinkType>  
  47. </definitions>  


Operation
操作. 说白了, 就是方法. 例如getAllUsers(). 可以接受参数和返回值, 当然参数和返回值在Web服务中叫消息.

PortType
端口类型. 由一些操作构成. 这个名字很容易让人摸不着头脑. 它其实就是我们说的Web Service: 你可以这样理解, 它相当于Java 中的类, 一个类中有很多方法, 这里就是操作. 更像工具类. 你给我参数告诉我调用那个方法, 然后我作完了将返回值给你. WSDL文件的根元素是<definitions>, 这个元素下面是一些portType元素. 其实WSDL就是一些端口类型的集合,或者说一些服务的集合.
如果更加直白的说:
Java: method --> class --> package 给其他Java程序使用
Web: operation --> port type --> wsdl 给其他任何Web Service的客户端使用.
类比一下把.</definitions>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值