WebServiceWSDLWeb

WSDL 文档仅仅是一个简单的 XML 文档。

它包含一系列描述某个 web service 的定义。

WSDL 文档是利用这些主要的元素来描述某个 web service 的:

元素定义
<portType> web service 执行的操作
<message> web service 使用的消息
<types> web service 使用的数据类型
<binding> web service 使用的通信协议

WSDL 端口

<portType> 元素是最重要的 WSDL 元素。

WSDL 消息

<message> 元素定义一个操作的数据元素。

每个消息均由一个或多个部件组成。可以把这些部件比作传统编程语言中一个函数调用的参数。

它可描述一个 web service、可被执行的操作,以及相关的消息。

可以把 <portType> 元素比作传统编程语言中的一个函数库(或一个模块、或一个类)。

由wsdl:types节点底下有若干个xsd:schema在xsd:schema下有若干个xsd:element来具体的说明里面到底有什么

例如

 <wsdl:types>
       <wsdl:documentation>
           Data types that are used for request and response messages.
       </wsdl:documentation>
       <xsd:schema targetNamespace="http://www.zzl.org/Convert">
           <xsd:element name="Request">
              <xsd:complexType>
                  <xsd:sequence>
                     <xsd:element name="Name" type="xsd:string" />
                     <xsd:element name="Address" type="xsd:string" />
                  </xsd:sequence>
              </xsd:complexType>
           </xsd:element>
       </xsd:schema>
    </wsdl:types>

操作类型

请求-响应是最普通的操作类型,不过 WSDL 定义了四种类型:

类型定义
One-way 此操作可接受消息,但不会返回响应。
Request-response 此操作可接受一个请求并会返回一个响应
Solicit-response 此操作可发送一个请求,并会等待一个响应。
Notification 此操作可发送一条消息,但不会等待响应。


然后在wsdl:portType 节点通过name属性去定义这个WebSerice的服务名;wsdl:portType底下会有wsdl:operation的name去具体的定义接口里面的方法名,然后wsdl:operation底下有两个子节点去定义输入和输出,并且类型为上面已经定义了 的message

例如

 <wsdl:portType name="ConvertService">
       <wsdl:documentation>
           The ConvertService contains the business operation.
       </wsdl:documentation>
       <wsdl:operation name="RevokeCert">
           <wsdl:documentation>
              The operation that do the business work.
           </wsdl:documentation>
           <wsdl:input message="tns:Request" />
           <wsdl:output message="tns:Response" />
           <wsdl:fault name="fault" message="tns:Fault" />
       </wsdl:operation>
  </wsdl:portType>

binding 元素有两个属性 - name 属性和 type 属性。

name 属性定义 binding 的名称,而 type 属性指向用于 binding 的端口,在这个例子中是 "glossaryTerms" 端口。

soap:binding 元素有两个属性 - style 属性和 transport 属性。

style 属性可取值 "rpc" 或 "document"。在这个例子中我们使用 document。transport 属性定义了要使用的 SOAP 协议。在这个例子中我们使用 HTTP。

operation 元素定义了每个端口提供的操作符。

对于每个操作,相应的 SOAP 行为都需要被定义。同时您必须如何对输入和输出进行编码。在这个例子中我们使用了 "literal"。

原文地址:https://www.cnblogs.com/chao538/p/5755484.html