• webservice wsdl语法基础


    XML-WSDL基础知识

    1. WSDL

    1.1. WSDL 简介

    1.1.1.    概述

    WSDL 指网络服务描述语言 (Web Services Description Language)

    WSDL 是基于 XML 的用于描述 Web Services 以及如何访问 Web Services 的语言。

    做为通讯协议,在web通讯中消息的格式被标准化的。WSDL为描述网络服务定义XML语法使交互的端点之间拥有信息交互的能力。WSDL服务定义为分布式系统提供了证据并且担任自动参与在应用通讯中处理的方法。

    WSDL文档定义服务作为络交互的端点或者ports的集合。在WSDL中,抽象的定义了端点和从网络部署或数据格式绑定分离的消息。允许重用抽象定义:messages(抽象的描述交互的数据);port typesoperations的集合)。对一个特定port type指定明确的协议和数据格式组成了一个可重用的binding。通过将一个网络地址关联到可重用的banging,定义了一个portport的集合定义了一个服务。因此,WSDL通过以下元素定义网络服务:

    ²  Type-包含使用类型系统(例如XSD)创建的数据类型的定义的容器。

    ²  Message-一个抽象的、典型的关于用于交互的数据定义。

    ²  Operation-一个服务支持的行为(方法)的抽象描述。

    ²  PortType-被一个或多个端点支持的一系列操作的抽象。

    ²  Binding-一个明确的协议和为特定porttype指定的数据格式。

    ²  Port-一个由网络地址和一个绑定组合的单一的端点

    ²  Service-相关端点的集合。

    WSDL没有采用新的类型定义语言。WSDL发现需要一个富类型系统来描述消息格式,并已XML Schema(XSD)作为其权威的类型系统。通过扩展,WSDL允许使用其他类型定义语言来描述消息。

    另外,WSDL定义了一个通过的binding机制,被用于连接指定的协议或数据格式或抽象消息/操作/端点的结构,允许被重用。

          除了核心服务定义框架,本文档介绍以下的协议和消息格式作为binding的扩展。

    ²  SOAP 1.1

    ²  HTTP GET / POST

    ²  MIME

    1.1.2.    一个WSDL例子

    <?xml version="1.0"?>

    <definitions name="StockQuote"

     

    targetNamespace="http://example.com/stockquote.wsdl"

              xmlns:tns="http://example.com/stockquote.wsdl"

              xmlns:xsd1="http://example.com/stockquote.xsd"

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

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

     

        <types>

           <schema targetNamespace="http://example.com/stockquote.xsd"

                  xmlns="http://www.w3.org/2000/10/XMLSchema">

               <element name="TradePriceRequest">

                  <complexType>

                      <all>

                          <element name="tickerSymbol" type="string"/>

                      </all>

                  </complexType>

               </element>

               <element name="TradePrice">

                  <complexType>

                      <all>

                          <element name="price" type="float"/>

                      </all>

                  </complexType>

               </element>

           </schema>

        </types>

     

        <message name="GetLastTradePriceInput">

            <part name="body" element="xsd1:TradePriceRequest"/>

        </message>

     

        <message name="GetLastTradePriceOutput">

            <part name="body" element="xsd1:TradePrice"/>

        </message>

     

        <portType name="StockQuotePortType">

            <operation name="GetLastTradePrice">

               <input message="tns:GetLastTradePriceInput"/>

               <output message="tns:GetLastTradePriceOutput"/>

            </operation>

        </portType>

     

        <binding name="StockQuoteSoapBinding" type="tns:StockQuotePortType">

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

            <operation name="GetLastTradePrice">

               <soap:operation soapAction="http://example.com/GetLastTradePrice"/>

               <input>

                   <soap:body use="literal"/>

               </input>

               <output>

                   <soap:body use="literal"/>

               </output>

            </operation>

        </binding>

     

        <service name="StockQuoteService">

            <documentation>My first service</documentation>

            <port name="StockQuotePort" binding="tns:StockQuoteBinding">

               <soap:address location="http://example.com/stockquote"/>

            </port>

        </service>

     

    </definitions>

    服务支持一个唯一的操作GetLastTradePrice,该操作通过SOAP1.1协议覆盖HTTP进行部署。请求参数为一个string类型的tickerSymbol,返回一个float的price。

    该例子使用固定的XML格式替代SOAP编码。

    1.1.3.    符号的约定

    1. 关键字

    a)     "MUST","REQUIRED", "SHALL"表示元素必需定义

    b)     "MUST NOT",  "SHALL NOT"表示绝对禁止的元素。

    c)     "SHOULD","RECOMMENDED"

    d)     "MAY", "OPTIONAL"表示可选的。

    e)     "SHOULD NOT","NOT RECOMMENDED"

    f)       

    1. 文档使用的命名空间前缀:

    prefix

    namespace URI

    definition

    wsdl

    http://schemas.xmlsoap.org/wsdl/

    WSDL namespace for WSDL framework.

    soap

    http://schemas.xmlsoap.org/wsdl/soap/

    WSDL namespace for WSDL SOAP binding.

    http

    http://schemas.xmlsoap.org/wsdl/http/

    WSDL namespace for WSDL HTTP GET & POST binding.

    mime

    http://schemas.xmlsoap.org/wsdl/mime/

    WSDL namespace for WSDL MIME binding.

    soapenc

    http://schemas.xmlsoap.org/soap/encoding/

    Encoding namespace as defined by SOAP 1.1

    soapenv

    http://schemas.xmlsoap.org/soap/envelope/

    Envelope namespace as defined by SOAP 1.1

    xsi

    http://www.w3.org/2000/10/XMLSchema-instance

    Instance namespace as defined by XSD

    xsd

    http://www.w3.org/2000/10/XMLSchema

    Schema namespace as defined by XSD .

    tns

    (various)

    The “this namespace” (tns) prefix is used as a convention to refer to the current document.

    (other)

    (various)

    All other namespace prefixes are samples only. In particular, URIs starting with “http://example.com” represent some application-dependent or context-dependent URI [4].

    3. WSDL使用非正式的语句描述XML语法

          语句的产生作为XML的实例,但是值指示通过数据类型代替。

          通配符:”?”-0个或1个;”*”-0个或多个;”+”-1个或多个,至少一个

          元素后加"…" (例如<element…/> or <element…>)表明上下文不相干的元素或属性被忽略

    1.2. WSDL 文档结构

    1.2.1.    文档结构

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

    元素

    定义

    <types>

    web service 使用的描述数据交互的数据类型,为了最大程度的平台中立性,WSDL 使用 XML Schema 语法来定义数据类型

    <message>

    web service 用于传输的数据的抽象。消息由逻辑部件组成,每个逻辑部件关联已定义的类型;每个消息均由一个或多个部件组成。可以把这些部件比作传统编程语言中一个函数调用的参数。

    <portType>

    描述一个 web service、可被执行的操作,以及相关的消息;可以把 <portType> 元素比作传统编程语言中的一个函数库(或一个模块、或一个类)。

    <binding>

    web service 使用的通信协议和数据格式,为每个port定义消息格式和协议细节。

    <port>

    指定绑定的地址,定义一个唯一的通讯端点。

    <service>

    聚集有关port的集合

    一个 WSDL 文档的主要结构是类似这样的:

    1.2.2.    文档命名和链接

    WSDL文件可以被复制一个可选的name属性,targetNamespace属性指定一个URL类型。

    通过使用import语句,WSDL允许在文档本地关联一个namesapce。

    <definitions .... >

        <import namespace="uri" location="uri"/> *

    </definitions>

    1.2.3.    编写风格

    通过import元素可以使一个service的不同元素分别定义至独立的文档,在需要的时候被导入。最大程度的重用服务的定义,以下示例显示了使用编写风格定义上述示例

    http://example.com/stockquote/stockquote.xsd

    <?xml version="1.0"?>

    <schema targetNamespace="http://example.com/stockquote/schemas"

           xmlns="http://www.w3.org/2000/10/XMLSchema">

          

        <element name="TradePriceRequest">

            <complexType>

                <all>

                    <element name="tickerSymbol" type="string"/>

                </all>

            </complexType>

        </element>

        <element name="TradePrice">

            <complexType>

                <all>

                    <element name="price" type="float"/>

                </all>

            </complexType>

        </element>

    </schema>

    http://example.com/stockquote/stockquote.wsdl

    <?xml version="1.0"?>

    <definitions name="StockQuote"

     

    targetNamespace="http://example.com/stockquote/definitions"

              xmlns:tns="http://example.com/stockquote/definitions"

              xmlns:xsd1="http://example.com/stockquote/schemas"

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

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

     

       <import namespace="http://example.com/stockquote/schemas"

               location="http://example.com/stockquote/stockquote.xsd"/>

     

        <message name="GetLastTradePriceInput">

            <part name="body" element="xsd1:TradePriceRequest"/>

        </message>

     

        <message name="GetLastTradePriceOutput">

            <part name="body" element="xsd1:TradePrice"/>

        </message>

     

        <portType name="StockQuotePortType">

            <operation name="GetLastTradePrice">

               <input message="tns:GetLastTradePriceInput"/>

               <output message="tns:GetLastTradePriceOutput"/>

            </operation>

        </portType>

    </definitions>

    http://example.com/stockquote/stockquoteservice.wsdl

    <?xml version="1.0"?>

    <definitions name="StockQuote"

     

    targetNamespace="http://example.com/stockquote/service"

              xmlns:tns="http://example.com/stockquote/service"

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

              xmlns:defs="http://example.com/stockquote/definitions"

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

     

       <import namespace="http://example.com/stockquote/definitions"

               location="http://example.com/stockquote/stockquote.wsdl"/>

     

        <binding name="StockQuoteSoapBinding" type="defs:StockQuotePortType">

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

            <operation name="GetLastTradePrice">

               <soap:operation soapAction="http://example.com/GetLastTradePrice"/>

               <input>

                   <soap:body use="literal"/>

               </input>

               <output>

                   <soap:body use="literal"/>

               </output>

            </operation>

        </binding>

     

        <service name="StockQuoteService">

            <documentation>My first service</documentation>

            <port name="StockQuotePort" binding="tns:StockQuoteBinding">

               <soap:address location="http://example.com/stockquote"/>

            </port>

        </service>

    </definitions>

          该示例分为三个文档定义:数据类型定义,概要定义,服务绑定。

    1.2.4.    语言扩展和绑定

    在WSDL中,绑定指定处理关联协或者对于概要实体(message,operation或portType)的数据格式信息。扩展点用于为一个特殊的协议和消息格式指定绑定信息,但是并不现实使用。扩展元素MUST使用一个不同于WSDL的XML命名空间。

    location

    Possible usage

    definitions

    为整个WSDL介绍额外的信息或者定义

    definitions/types

    指定message在type系统中的格式

    definitions/service

    为服务介绍额外的信息和定义

    definitions/service/port

    为port指定地址

    definitions/binding

    在port type范围内,提供协议指定应用于操作的信息

    definitions/binding/operation

    提供指定应用与input和output消息的信息

    definitions/binding/operation/input

    提供关于概要信息部分如何映射到明确协议和数据格式的明细。

    为输入消息提供额外的协议指定信息

    definitions/binding/operation/output

    提供关于概要信息部分如何映射到明确协议和数据格式的明细

    为输出消息提供额外的协议指定信息

    definitions/binding/operation/fault

    提供关于概要信息部分如何映射到明确协议和数据格式的明细

    为错误信息提供额外的协议指定信息

    1.2.5.     文档化

    WSDL使用可选的wsdl:document元素作为用于可读性文档化的一个容器。该元素允许在任何WSDL语言元素中使用。

     

    1.2.6.    WSDL 实例

    这是某个 WSDL 文档的简化的片段:

    <wsdl:definitions name="nmtoken"? targetNamespace="uri"?>

        <import namespace="uri" location="uri"/>*

        <wsdl:documentation .... /> ?

        <wsdl:types> ?

            <wsdl:documentation .... />?

            <xsd:schema .... />*

            <-- extensibility element --> *

        </wsdl:types>

     

        <wsdl:message name="nmtoken"> *

            <wsdl:documentation .... />?

            <part name="nmtoken" element="qname"? type="qname"?/> *

        </wsdl:message>

     

        <wsdl:portType name="nmtoken">*

            <wsdl:documentation .... />?

            <wsdl:operation name="nmtoken">*

               <wsdl:documentation .... /> ?

               <wsdl:input name="nmtoken"? message="qname">?

                   <wsdl:documentation .... /> ?

               </wsdl:input>

               <wsdl:output name="nmtoken"? message="qname">?

                   <wsdl:documentation .... /> ?

               </wsdl:output>

               <wsdl:fault name="nmtoken" message="qname"> *

                   <wsdl:documentation .... /> ?

               </wsdl:fault>

            </wsdl:operation>

        </wsdl:portType>

     

        <wsdl:binding name="nmtoken" type="qname">*

            <wsdl:documentation .... />?

            <-- extensibility element --> *

            <wsdl:operation name="nmtoken">*

               <wsdl:documentation .... /> ?

               <-- extensibility element --> *

               <wsdl:input> ?

                   <wsdl:documentation .... /> ?

                   <-- extensibility element -->

               </wsdl:input>

               <wsdl:output> ?

                   <wsdl:documentation .... /> ?

                   <-- extensibility element --> *

               </wsdl:output>

               <wsdl:fault name="nmtoken"> *

                   <wsdl:documentation .... /> ?

                   <-- extensibility element --> *

               </wsdl:fault>

            </wsdl:operation>

        </wsdl:binding>

     

        <wsdl:service name="nmtoken"> *

            <wsdl:documentation .... />?

            <wsdl:port name="nmtoken" binding="qname"> *

               <wsdl:documentation .... /> ?

               <-- extensibility element -->

            </wsdl:port>

            <-- extensibility element -->

        </wsdl:service>

     

        <-- extensibility element --> *

     

    </wsdl:definitions>

     

    1.3. WSDL Types

    Types元素封装了关于数据交互信息的数据类型定义。

    为了实现最大程度的协同工作能力和平台无关,WSDL比较喜欢使用XSD作为权威的类型系统,并且作为固有的类型系统。

    <definitions .... >
        <types>
            <xsd:schema .... />*
        </types>
    </definitions>

    XSD类型系统能够用于定义在消息中定义类型。如果对相同的消息指定多个绑定,或者只有一个绑定但是绑定类型对应的类型系统并没有广泛使用,推荐遵循以下内容使用XSD:

    ²  使用element形式(没有属性)

    ²  不包含对于编码来说独特的属性或元素(例如:对于与消息的概要内容来说什么也没有做)。一些例子有:saop:root,soap:encodingStyle,xmi:id,xmi:name

    ²  数组类型需要扩展SOAP1.1 encoding 结构(http://schemas.xmlsoap.org/soap/encoding/)的数组类型的定义,为数组类型使用名字ArraryofXXX(XXX标示数组元素的基本类型)。通过使用soapenc:arrayType属性的默认值指定元素的类型和元素的规模。当前XSD不支持包含QName值的属性的默认值。

    ²  使用xsd:anyTYpe标示字段/参数可是是任何类型。

     

    期望只有一种类型系统能够描述所有的类型是不现实的,WSDL允许类型系统凭借扩展的元素增加。扩展元素在types元素下定义产生一个类型定义的容器元素。

    <definitions .... >
        <types>
            <-- type-system extensibility element --> *
        </types>
    </definitions>

    1.4. WSDL Messages

    Messages由一个活多个逻辑部分组成,每个逻辑部分使用message-typing属性关联类型系统对应的一个类型。一组message-typing属性是可扩展的。WSDL使用XSD定义了数个message-typing属性:

    ²  element:使用一个QName指定XSD元素

    ²  type:使用一个QName指定一个XSD的简单类型或复制类型。

    其他message-type属性只要使用不同于WSDL的namespace定义。绑定扩展的属性也使用message-typing属性。

    定义message的语法如下:

    <definitions .... >
        <message name="nmtoken"> *
            <part name="nmtoken" element="qname"? type="qname"?/> *
        </message>
    </definitions>

    用黑标标出部分为message-type对应的属性。

    message元素的name属性指定了一个唯一的message名字。

    part元素的name属性提供了在message中的一个唯一的part名字。

    1.4.1.    Message Parts

    Parts是描述Message逻辑抽象内容的一种机制。一个binding可能指定part的名字为了详述关于part的绑定信息。例如,如果使用RPC(远程过程调用)定义一个message,part可能代表了信息的一个参数。无论如何,为了确定part的真实意义必须检查binding。

    如果message拥有多个逻辑单元,那么就有多个part元素被使用。例如,下面的message有一个Purchase Order和一个Invoice组成:

    <definitions .... >

        <types>

            <schema .... >

               <element name="PO" type="tns:POType"/>

               <complexType name="POType">

                   <all>

                       <element name="id" type="string/>

                       <element name="name" type="string"/>

                       <element name="items">

                           <complexType>

                               <all>

                                   <element name="item" type="tns:Item" minOccurs="0" maxOccurs="unbounded"/>

                               </all>

                           </complexType>

                       </element>

                  </all>

               </complexType>

     

               <complexType name="Item">

                   <all>

                       <element name="quantity" type="int"/>

                       <element name="product" type="string"/>

                   </all>

               </complexType>

               <element name="Invoice" type="tns:InvoiceType"/>

               <complexType name="InvoiceType">

                   <all>

                       <element name="id" type="string"/>

                   </all>

               </complexType>

            </schema>

        </types>

     

        <message name="PO">

            <part name="po" element="tns:PO"/>

            <part name="invoice" element="tns:Invoice"/>

        </message>

    </definitions>

    无论如何,如果消息的内容十分复杂的,那么使用指定的由type system直接定义的message综合结构。在这种情况下,只有一个part被指定。在以下的例子中,body及时purchase order,也是一组invoice

    <definitions .... >
        <types>
            <schema .... >
               <complexType name="POType">
                   <all>
                       <element name="id" type="string/>
                       <element name="name" type="string"/>
                       <element name="items">
                           <complexType>
                               <all>
                                   <element name="item" type="tns:Item" minOccurs="0" maxOccurs="unbounded"/>
                               </all>                          
                           </complexType>
                       </element>
                   </all>
               </complexType>
     
               <complexType name="Item">
                   <all>
                       <element name="quantity" type="int"/>
                       <element name="product" type="string"/>
                   </all>
               </complexType>
               <complexType name="InvoiceType">
                   <all>
                       <element name="id" type="string"/>
                   </all>
               </complexType>
     
               <complexType name="Composite">
                   <choice>
                       <element name="PO" minOccurs="1" maxOccurs="1" type="tns:POType"/>
                       <element name="Invoice" minOccurs="0" maxOccurs="unbounded" type="tns:InvoiceType"/>
                   </choice>
               </complexType>
            </schema>
        </types>
     
        <message name="PO">
            <part name="composite" type="tns:Composite"/>
        </message>
    </definitions>

    1.4.2.    Abstract vs. Concrete Messages

    Message定义一般被考虑是一个message内容抽象定义。一个message绑定描述了抽象内容如何映射到明确的格式,尽管如此,在一些例子中,抽象定义对于一个或多个绑定来说非常接近明其明确的代表,因此binding可能提供较少的或不提供映射信息。无论如何,对于那个相同message定义的另外的绑定可能需要扩展映射信息,理由是,直到检查绑定后才能确定当前的message有多抽象。

    1.5. WSDL Port Types

    <portType> 元素是最重要的 WSDL 元素。它可描述一个 web service、可被执行的操作,以及相关的消息。端口定义了指向某个 web service 的连接点。可以把该元素比作传统编程语言中的一个函数库(或一个模块、或一个类),而把每个操作比作传统编程语言中的一个函数。

          Port 类型是一个包含抽象operation和抽象messsage的集合。

    <wsdl:definitions .... >
    <wsdl:portType name="nmtoken">
       <!—通过name属性命名operation-->
            <wsdl:operation name="nmtoken" .... /> *
        </wsdl:portType>
    </wsdl:definitions>

        Port type的name属性提供了在WSDL文件中,对于所有port type来说唯一的名字。

    1.5.1.    操作类型

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

    类型

    定义

    One-way

    此操作可接受消息,但不会返回响应。

    Request-response

    此操作可接受一个请求并会发送一个相关的消息

    Solicit-response

    此操作可发送一个请求,并会接受一个相关的响应。

    Notification

    此操作可发送一条消息,但不会等待响应。

    WSDL指定了这些原始的操作,然而request/response或者solicit/response在理论上可以使用两个one-way的message模仿,因为以下原因,模型原始的操作是很有用的:

    ²  非常平凡的

    ²  Sequence能够被关联,不需要引入更多复杂的流信息。

    ²  对于响应同步请求的返回,很多节点只需要接受message

    ²  当渴望一个flow定义,能够简单的从这些原始操作得到

    尽管 request/response 或 solicit/response 在WSDL文件中被逻辑关联,一个给定的binding描述了明确的关联信息.例如,request和response messages 可以再一个或两个实际通讯的网络中进行交互。

    尽管基本的WSDL结构支持4中传播原型的binding。WSDL仅仅为One-way和Request-response原型定义了binding。WSDL binding扩展允许使用Solicit-response 或 Notification。

    Message属性是QName类型

    1.5.2.    One-way 操作

    One-Way操作的语法:

    <wsdl:definitions .... > <wsdl:portType .... > *

            <wsdl:operation name="nmtoken">

               <wsdl:input name="nmtoken"? message="qname"/>

            </wsdl:operation>

        </wsdl:portType >

    </wsdl:definitions>

          Input元素详述了one-way操作的抽象的message格式。

    1.5.3.    Request-response 操作

    request-response操作的语法:

    <wsdl:definitions .... >

        <wsdl:portType .... > *

            <wsdl:operation name="nmtoken" parameterOrder="nmtokens">

               <wsdl:input name="nmtoken"? message="qname"/>

               <wsdl:output name="nmtoken"? message="qname"/>

               <wsdl:fault name="nmtoken" message="qname"/>*

            </wsdl:operation>

        </wsdl:portType >

    </wsdl:definitions>

    Input和output元素分别表示request和response的抽象的消息格式。可选项fault元素表示作为操作结果输出的错误信息的抽象消息格式。

    request-response操作是一个抽象的概念,一个特殊的binding必须考虑如何在一个通讯(例如,一个HTTP 请求/响应)或两个独立的通讯(例如,两个HTTP请求)中真正的发送消息。

    1.5.4.    Solicit-response 操作

    solicit-response操作的语法:

    <wsdl:definitions .... >

        <wsdl:portType .... > *

            <wsdl:operation name="nmtoken" parameterOrder="nmtokens">

               <wsdl:output name="nmtoken"? message="qname"/>

               <wsdl:input name="nmtoken"? message="qname"/>

               <wsdl:fault name="nmtoken" message="qname"/>*

            </wsdl:operation>

        </wsdl:portType >

    </wsdl:definitions>

    Output和input元素分别标示一个请求和其响应的抽象的message格式。可选项fault元素表示作为操作结果输出的错误信息的抽象消息格式。

    Note:solicit-response是一个抽象的概念,一个特定的binding必须考考虑如何在一个通讯(例如,一个HTTP 请求/响应)或两个独立的通讯(例如,两个HTTP请求)中真正的发送消息。

    1.5.5.    Notification 操作

    Notification操作的语法:

    <wsdl:definitions .... >

        <wsdl:portType .... > *

            <wsdl:operation name="nmtoken">

               <wsdl:output name="nmtoken"? message="qname"/>

            </wsdl:operation>

        </wsdl:portType >

    </wsdl:definitions>

        Output参数指定了notification操作的抽象的message格式。

    1.5.6.    Operation中name元素

    Input和output元素的name属性为port Type中的input和output元素提供了一个唯一的名字。

     

    In order to avoid having to name each input and output element within an operation, WSDL provides some default values based on the operation name. If the name attribute is not specified on a one-way or notification message, it defaults to the name of the operation. If the name attribute is not specified on the input or output messages of a request-response or solicit-response operation, the name defaults to the name of the operation with "Request"/"Solicit" or "Response" appended, respectively.

    Each fault element must be named to allow a binding to specify the concrete format of the fault message. The name of the fault element is unique within the set of faults defined for the operation.

    2.4.6 Parameter Order within an Operation

    Operations do not specify whether they are to be used with RPC-like bindings or not. However, when using an operation with an RPC-binding, it is useful to be able to capture the original RPC function signature. For this reason, a request-response or solicit-response operation MAY specify a list of parameter names via the parameterOrder attribute (of type nmtokens). The value of the attribute is a list of message part names separated by a single space. The value of the parameterOrder attribute MUST follow the following rules:

    • The part name order reflects the order of the parameters in the RPC signature
    • The return value part is not present in the list
    • If a part name appears in both the input and output message, it is an in/out parameter
    • If a part name appears in only the input message, it is an in parameter
    • If a part name appears in only the output message, it is an out parameter

    Note that this information serves as a "hint" and may safely be ignored by those not concerned with RPC signatures. Also, it is not required to be present, even if the operation is to be used with an RPC-like binding.

    1.6.  WSDL 端口

    WSDL 端口可描述由某个 web service 提供的界面(合法操作)。

    1.6.1.    WSDL 端口

    1.6.2.    One-Way 操作

    一个 one-way 操作的例子:

    <message name="newTermValues">

       <part name="term" type="xs:string"/>

       <part name="value" type="xs:string"/>

    </message>

     

    <portType name="glossaryTerms">

       <operation name="setTerm">

          <input name="newTerm" message="newTermValues"/>

       </operation>

    </portType >

    在这个例子中,端口 "glossaryTerms" 定义了一个名为 "setTerm" 的 one-way 操作。

    这个 "setTerm" 操作可接受新术语表项目消息的输入,这些消息使用一条名为 "newTermValues" 的消息,此消息带有输入参数 "term" 和 "value"。不过,没有为这个操作定义任何输出。

    1.6.3.    Request-Response 操作

    一个 request-response 操作的例子:

    <message name="getTermRequest">

       <part name="term" type="xs:string"/>

    </message>

     

    <message name="getTermResponse">

       <part name="value" type="xs:string"/>

    </message>

     

    <portType name="glossaryTerms">

      <operation name="getTerm">

        <input message="getTermRequest"/>

        <output message="getTermResponse"/>

      </operation>

    </portType>

    在这个例子中,端口 "glossaryTerms" 定义了一个名为 "getTerm" 的 request-response 操作。

    "getTerm" 操作会请求一个名为 "getTermRequest" 的输入消息,此消息带有一个名为 "term" 的参数,并将返回一个名为 "getTermResponse" 的输出消息,此消息带有一个名为 "value" 的参数。

    1.7. WSDL 绑定

    WSDL 绑定可为 web service 定义消息格式和协议细节。.

    WSDL提供了一个模型和描述Web Services的XML格式。WSDL SOAP1.1绑定描述了对于SOAP1.1协议的绑定的扩展。该绑定被规定为方便的将使用SOAP1.1协议描述的实现从WSDL1.1迁移到WSDL2.0。并且绑定允许使用者继续使用SOAP1.1协议。

    1.7.1.    符号约定

    描述了使用一系列命名空间前缀贯穿全文。选择任何命名空间前缀是随意的并且没有特别重要的语义。

    前缀

    命名空间

    wsdl

    "http://www.w3.org/ns/wsdl"

    wsoap

    "http://www.w3.org/ns/wsdl/soap"

    whttp

    "http://www.w3.org/ns/wsdl/http"

    xs

    "http://www.w3.org/2001/XMLSchema"

    1.7.2.    SOAP1.1

    通过WSDL辅助的SOAP绑定扩展,SOAP1.1绑定能够使Web Service应用使用SOAP1.1.这类绑定有以下的支持:

          消息装换模型:支持两种消息消息转换模型:In-Out和In-Only

          SOAP模块:支持SOAP模块并且允许用户使用SOAP Module组件指示SOAP模块。“SOAP Module”(也被认为是SOAP扩展),指定语法和一个或多个SOAP头的语义。要求在SOAP1.1绑定中指定一个SOAP Module。

          SOAP1.1 HTTP绑定:

    • SOAP 1.1 HTTP Binding - supports the SOAP 1.1 HTTP binding defined in Section 6, SOAP 1.1 specification [SOAP11]. This is indicated by assigning the URI "http://www.w3.org/2006/01/soap11/bindings/HTTP/" to the {soap underlying protocol} property.

    The value of the {soap action} property, if present, identifies the value of the SOAP 1.1 SOAPAction HTTP request header field, Section 6.1.1, SOAP 1.1 specification [SOAP11].

    The values of {http location} properties are ignored for SOAP 1.1 HTTP binding.

    Note:

    If the Interface Operation component's {message exchange pattern} property has the value "http://www.w3.org/ns/wsdl/in-only" and the Binding component's {soap underlying protocol} property has the value"http://www.w3.org/2006/01/soap11/bindings/HTTP/", then the HTTP response is undefined. For specific guidance on what the HTTP response ought to be, implementers are referred to the Basic Profile [BP10] and/or the latest version of this specification(s).

    • Other SOAP 1.1 Underlying Protocols - supports other SOAP 1.1 underlying protocols. Other values can be used for the {soap underlying protocol} property in conjunction with the SOAP 1.1 binding provided that the semantics of such protocols are consistent with this binding.

    The values of {soap mep default}, {soap mep} and {soap fault subcodes} properties are ignored for SOAP 1.1 binding.

     

    1.7.3.    绑定到 SOAP

    一个 请求 - 响应 操作的例子:

    <message name="getTermRequest">

       <part name="term" type="xs:string" />

    </message>

     

    <message name="getTermResponse">

       <part name="value" type="xs:string" />

    </message>

     

    <portType name="glossaryTerms">

      <operation name="getTerm">

          <input message="getTermRequest" />

          <output message="getTermResponse" />

      </operation>

    </portType>

     

    <binding type="glossaryTerms" name="b1">

    <soap:binding style="document"

    transport="http://schemas.xmlsoap.org/soap/http" />

      <operation>

        <soap:operation

         soapAction="http://example.com/getTerm" />

        <input>

          <soap:body use="literal" />

        </input>

        <output>

          <soap:body use="literal" />

        </output>

      </operation>

    </binding>

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

    ²  name 属性定义 binding 的名称,

    ²  type 属性指向用于 binding 的端口,在这个例子中是 "glossaryTerms" 端口。

    soap:binding 元素有两个属性

    ²  style 属性: 可取值 "rpc" 或 "document"。在这个例子中我们使用 document。

    ²  transport 属性: 定义了要使用的 SOAP 协议。在这个例子中我们使用 HTTP。

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

    1.8. WSDL 和 UDDI

    UDDI 是一种目录服务,企业可以使用它对 Web services 进行注册和搜索。

    UDDI,英文为 "Universal Description, Discovery and Integration",可译为通用描述、发现与集成服务

    1.8.1.    什么是 UDDI?

    UDDI 是一个独立于平台的框架,用于通过使用 Internet 来描述服务,发现企业,并对企业服务进行集成。

    ²  UDDI 指的是通用描述、发现与集成服务

    ²  UDDI 是一种用于存储有关 web services 的信息的目录。

    ²  UDDI 是一种由 WSDL 描述的 web services 界面的目录。

    ²  UDDI 经由 SOAP 进行通信

    ²  UDDI 被构建入了微软的 .NET 平台

    1.8.2.    UDDI 基于什么?

    UDDI 使用 W3C 和 IETF(Internet Engineering Task Force) 的因特网标准,比如 XML、HTTP 和 DNS 协议。

    UDDI 使用 WSDL 来描述到达 web services 的界面

    此外,通过采用 SOAP,还可以实现跨平台的编程特性,大家知道,SOAP 是 XML 的协议通信规范,可在 W3C 的网站找到相关的信息。

    1.8.3.    UDDI 的好处

    任何规模的行业或企业都能得益于 UDDI。

    在 UDDI 之前,还不存在一种 Internet 标准,可以供企业为它们的企业和伙伴提供有关其产品和服务的信息。也不存在一种方法,来集成到彼此的系统和进程中。

    UDDI 规范帮助我们解决的问题:

    ²  使得在成百万当前在线的企业中发现正确的企业成为可能

    ²  定义一旦首选的企业被发现后如何启动商业

    ²  扩展新客户并增加对目前客户的访问

    ²  扩展销售并延伸市场范围

    ²  满足用户驱动的需要,为在全球 Internet 经济中快速合作的促进来清除障碍

    1.8.4.    UDDI 如何被使用

    假如行业发布了一个用于航班比率检测和预订的 UDDI 标准,航空公司就可以把它们的服务注册到一个 UDDI 目录中。然后旅行社就能够搜索这个 UDDI 目录以找到航空公司预订界面。当此界面被找到后,旅行社就能够立即与此服务进行通信,这样由于它使用了一套定义良好的预订界面。

    1.8.5.    谁在支持 UDDI?

    UDDI 是一个跨行业的研究项目,由所有主要的平台和软件提供商驱动,比如:Dell, Fujitsu, HP, Hitachi, IBM, Intel, Microsoft, Oracle, SAP, 以及 Sun, 它既是一个市场经营者的团体,也是一个电子商务的领导者。

    已有数百家公司参与了这个 UDDI 团体。

    1.9. 完整的 WSDL 语法

    描述于 W3C 工作草案的完整 WSDL 1.2 语法已列在下面:

    <wsdl:definitions name="nmtoken"? targetNamespace="uri">
     
        <import namespace="uri" location="uri"/> *
        
        <wsdl:documentation .... /> ?
     
        <wsdl:types> ?
            <wsdl:documentation .... /> ?
            <xsd:schema .... /> *
        </wsdl:types>
     
        <wsdl:message name="ncname"> *
            <wsdl:documentation .... /> ?
            <part name="ncname" element="qname"? type="qname"?/> *
        </wsdl:message>
     
        <wsdl:portType name="ncname"> *
            <wsdl:documentation .... /> ?
            <wsdl:operation name="ncname"> *
                <wsdl:documentation .... /> ?
                <wsdl:input message="qname"> ?
                    <wsdl:documentation .... /> ?
                </wsdl:input>
                <wsdl:output message="qname"> ?
                    <wsdl:documentation .... /> ?
                </wsdl:output>
                <wsdl:fault name="ncname" message="qname"> *
                    <wsdl:documentation .... /> ?
                </wsdl:fault>
            </wsdl:operation>
        </wsdl:portType>
     
        <wsdl:serviceType name="ncname"> *
            <wsdl:portType name="qname"/> +
        </wsdl:serviceType>
     
        <wsdl:binding name="ncname" type="qname"> *
            <wsdl:documentation .... /> ?
            <-- binding details --> *
            <wsdl:operation name="ncname"> *
                <wsdl:documentation .... /> ?
                <-- binding details --> *
                <wsdl:input> ?
                    <wsdl:documentation .... /> ?
                    <-- binding details -->
                </wsdl:input>
                <wsdl:output> ?
                    <wsdl:documentation .... /> ?
                    <-- binding details --> *
                </wsdl:output>
                <wsdl:fault name="ncname"> *
                    <wsdl:documentation .... /> ?
                    <-- binding details --> *
                </wsdl:fault>
            </wsdl:operation>
        </wsdl:binding>
     
        <wsdl:service name="ncname" serviceType="qname"> *
            <wsdl:documentation .... /> ?
            <wsdl:port name="ncname" binding="qname"> *
                <wsdl:documentation .... /> ?
                <-- address details -->
            </wsdl:port>
        </wsdl:service>
     
    </wsdl:definitions>

    1.10.    总结

    1.10.1.   WSDL 概要

    本教程已为您讲解了如何创建可描述 web 服务的 WSDL 文档。它也规定了服务的位置和服务所提供的操作(或方法)。

    您已经学习到如何为 web 服务定义消息格式和协议细节。

    您也学习了可通过 UDDI 来注册和搜索 web 服务。

    1.10.2.   您已经学习了 WSDL,下一步呢?

    下一步应该学习 SOAP 和 Web Services。

    SOAP 是一种基于 XML 的简易协议,允许应用程序通过 HTTP 来交换信息。

    或者更简单地讲,SOAP 是用于访问 web 服务的协议。

    如果您希望学习更多有关 SOAP 的知识,请访问我们的 SOAP 教程

    Web services 可把您的应用程序转换为 web 应用程序。通过使用 XML,可以在应用程序间传送消息。

     

  • 相关阅读:
    【STM32F429】第4章 RTX5操作系统移植(MDK AC5)
    【STM32F407】第4章 RTX5操作系统移植(MDK AC5)
    【STM32H7】第3章 RTX5操作系统介绍
    【STM32F429】第3章 RTX5操作系统介绍
    【STM32F407】第3章 RTX5操作系统介绍
    【STM32H7】第2章 初学RTX5准备工作
    【STM32F429】第2章 初学RTX5准备工作
    Hystrix解析(一)
    Eureka源码解析(五)
    Eureka源码分析(四)
  • 原文地址:https://www.cnblogs.com/LCCRNblog/p/4079742.html
Copyright © 2020-2023  润新知