WSDL例子及内部元素的简单介绍

先看例子再做解释:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns
="http://www.jsoso.com/wstest" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns
="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://www.jsoso.com/wstest"
name
="Example">
<types>
<xsd:schema>
<xsd:import namespace="http://www.jsoso.com/wstest"
schemaLocation
="http://localhost:8080/hello?xsd=1"></xsd:import>
</xsd:schema>
</types>
<message name="toSayHello">
<part name="userName" type="xsd:string"></part>
</message>
<message name="toSayHelloResponse">
<part name="returnWord" type="xsd:string"></part>
</message>
<message name="sayHello">
<part name="person" type="tns:person"></part>
<part name="arg1" type="xsd:string"></part>
</message>
<message name="sayHelloResponse">
<part name="personList" type="tns:personArray"></part>
</message>
<message name="HelloException">
<part name="fault" element="tns:HelloException"></part>
</message>
<portType name="Example">
<operation name="toSayHello" parameterOrder="userName">
<input message="tns:toSayHello"></input>
<output message="tns:toSayHelloResponse"></output>
</operation>
<operation name="sayHello" parameterOrder="person arg1">
<input message="tns:sayHello"></input>
<output message="tns:sayHelloResponse"></output>
<fault message="tns:HelloException" name="HelloException"></fault>
</operation>
</portType>
<binding name="ExamplePortBinding" type="tns:Example">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"
style
="rpc"></soap:binding>
<operation name="toSayHello">
<soap:operation soapAction="sayHello"></soap:operation>
<input>
<soap:body use="literal" namespace="http://www.jsoso.com/wstest"></soap:body>
</input>
<output>
<soap:body use="literal" namespace="http://www.jsoso.com/wstest"></soap:body>
</output>
</operation>
<operation name="sayHello">
<soap:operation soapAction="sayHello"></soap:operation>
<input>
<soap:body use="literal" namespace="http://www.jsoso.com/wstest"></soap:body>
</input>
<output>
<soap:body use="literal" namespace="http://www.jsoso.com/wstest"></soap:body>
</output>
<fault name="HelloException">
<soap:fault name="HelloException" use="literal"></soap:fault>
</fault>
</operation>
</binding>
<service name="Example">
<port name="ExamplePort" binding="tns:ExamplePortBinding">
<soap:address location="http://localhost:8080/hello"></soap:address>
</port>
</service>
</definitions>

主要元素:
  <types>
    web service使用的数据类型,
    独立于机器和语言的类型定义
    这些定义将被<message>标签所使用。
  <message>
    web service使用的消息,
    定义了web service方法的参数
    在WSDL中,输入、输出参数分开定义,使用不同的<message>标签标示。
    <message>标签定义的输入输出参数将被<portType>标签使用。
  <portType>
    web service执行的操作(即方法定义)
    该标签引用<message>标签的定义来描述函数签名(操作名、输入参数、输出参数)
  <binding>
    web service使用的通信协议。
  <portType>
    标签中定义的每一操作在此绑定实现。
  <service>
    该标签确定每一<binding>标签的端口地址

注解1:
  WSDL文档可以分为两部分:
    顶部分由抽象定义组成,
    底部分则由具体描述组成。
    抽象部分以独立于平台和语言的方式定义SOAP消息;具体部分,如数据的序列化等,包含具体的定义。
    <types>、<message>、<portType>属于抽象定义层;
    <binding>、<service>属于具体定义层。
  所有的抽象可以是单独存在于别的文件中,也可以从主文档中导入。

注解2:
  <definitions>定义了文档中用到的各个xml元素的namespace缩写,也界定了本文档自己的 targetNamespace="http://www.jsoso.com/wstest".
  这意味着其它的XML要引用当前XML中的元素时,要声明这个namespace。
  注意xmlns:tns="http://www.jsoso.com/wstest"这个声明,它标示了使用tns这个前缀指向自身的命名空间。

注解3:
  <binding>标签是完整描述协议、序列化和编码的地方,表示处理数据传输的物理实现。
  <soap:binding>的transport和style属性定义了Web Service的通讯协议和SOAP的请求风格RPC。

来源:
  http://blog.csdn.net/simbi/article/details/6231151
  http://wenku.baidu.com/view/52376cb9fd0a79563c1e72f2.html



posted @ 2012-02-26 13:50  万法自然~  阅读(864)  评论(0编辑  收藏  举报