DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> XML學習教程 >> XML與XSLT
XML 模式:WSDL 服務描述語言
編輯:XML與XSLT     

Web 服務描述語言(Web Services Description Language,WSDL)提供了一種描述 Web 服務(多使用 SOAP)的簡便方法,讓你能描述基於 SOAP 標準所提供的服務與接口。

舉例來說,你可以創建一個描述某服務器上所提供服務的 WSDL 文件,再把它分發給需要使用這些服務的消費者。消費者透過閱讀與解析 WSDL,就能了解使用這些 Web 服務所需知道的一切:可交換的數據類型、參數,以及返回的各種錯誤與其他信息。

下面沿用 W3C 的例子,展示不同遠程函數與交換數據如何以結構化的 XML 定義處理:

<?xml version="1.0"?>
<!-- 根元素 wsdl:definitions 定義一組相關服務 -->
<wsdl:definitions name="EndorsementSearch"
    targetNamespace="https://namespaces.snowboard-info.com"
    xmlns:es="https://www.snowboard-info.com/EndorsementSearch.wsdl"
    xmlns:esxsd="https://schemas.snowboard-info.com/EndorsementSearch.xsd"
    xmlns:soap="https://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:wsdl="https://schemas.xmlsoap.org/wsdl/">
  <!-- wsdl:types 封裝通信類型的 schema 定義,此處使用 xsd -->
  <wsdl:types>
    <xsd:schema targetNamespace="https://namespaces.snowboard-info.com"
                xmlns:xsd="https://www.w3.org/1999/XMLSchema">
      <xsd:element name="GetEndorsingBoarder">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="manufacturer" type="string"/>
            <xsd:element name="model" type="string"/>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
      ...
    </xsd:schema>
  </wsdl:types>
  <!-- wsdl:message 描述潛在的事務 -->
  <wsdl:message name="GetEndorsingBoarderRequest">
    <wsdl:part name="body" element="esxsd:GetEndorsingBoarder"/>
  </wsdl:message>
  <!-- wsdl:portType 描述操作中的消息 -->
  <wsdl:portType name="GetEndorsingBoarderPortType">
    <wsdl:operation name="GetEndorsingBoarder">
      <wsdl:input message="es:GetEndorsingBoarderRequest"/>
      <wsdl:output message="es:GetEndorsingBoarderResponse"/>
      <wsdl:fault message="es:GetEndorsingBoarderFault"/>
    </wsdl:operation>
  </wsdl:portType>
  <!-- wsdl:binding 為服務聲明序列化協議 -->
  <wsdl:binding name="EndorsementSearchSoapBinding" type="es:GetEndorsingBoarderPortType">
    <soap:binding style="document" transport="https://schemas.xmlsoap.org/soap/http"/>
    ...
  </wsdl:binding>
  <!-- wsdl:service 命名一個新服務 -->
  <wsdl:service name="EndorsementSearchService">
    <wsdl:port name="GetEndorsingBoarderPort" binding="es:EndorsementSearchSoapBinding">
      <soap:address location="https://www.snowboard-info.com/EndorsementSearch"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

這個 WSDL 聲明了消息類型、默認數據類型與內容,以及交換的數據結構。訪問服務器上 SOAP 結構所需的一切信息都能從中找到。大多數語言與環境都提供讀取與解析 WSDL 的機制,以確定可用的函數與數據交換方式。

更強大的是,透過合適的 WSDL 生成程序,還能自動生成發送請求、並格式化響應所需的代碼。WSDL 與 SOAP 結合,構成了一個強而有力的遠程過程調用系統。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved