WSDL 2.0文件範例


以下是以XML格式表示WSDL 2.0 文件的簡單範例,檔案:hello_wsdl_20_soap.wsdl 的內容如下 -

<?xml version="1.0"?> 
<wsdl:description xmlns:wsdl="http://www.w3.org/ns/wsdl"
  xmlns:wsoap= "http://www.w3.org/ns/wsdl/soap"
  xmlns:hy="http://www.herongyang.com/Service/"
  targetNamespace="http://www.herongyang.com/Service/">

  <wsdl:documentation>
    Hello_WSDL_20_SOAP.wsdl
    Copyright (c) 2009 HerongYang.com, All Rights Reserved.
  </wsdl:documentation>

  <wsdl:types>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      targetNamespace="https://www.tw511.com/service/">
      <xsd:element name="Hello" type="xsd:string"/>    
      <xsd:element name="HelloResponse" type="xsd:string"/>    
    </xsd:schema>    
  </wsdl:types>

  <wsdl:interface name="helloInterface" >
    <wsdl:operation name="Hello" 
      pattern="http://www.w3.org/ns/wsdl/in-out" 
      style="http://www.w3.org/ns/wsdl/style/iri">
      <wsdl:input messageLabel="In" 
        element="hy:Hello" />
      <wsdl:output messageLabel="Out" 
        element="hy:HelloResponse" />
    </wsdl:operation>
  </wsdl:interface>

  <wsdl:binding name="helloBinding" 
    interface="hy:helloInterface"
    type="http://www.w3.org/ns/wsdl/soap"
    wsoap:protocol="http://www.w3.org/2003/05/soap/bindings/HTTP/">
    <wsdl:operation ref="hy:Hello" 
      wsoap:mep="http://www.w3.org/2003/05/soap/mep/soap-response"/>
  </wsdl:binding>

  <wsdl:service name="helloService" 
    interface="hy:helloInterface">
    <wsdl:endpoint name="helloEndpoint" 
      binding="hy:helloBinding"
address="h/"/>
  </wsdl:service>

</wsdl:description>

在這個WSDL 2.0範例文件中,

  • Web服務helloService使用端點helloEndpoint定義,它的存取地址是:h/
  • 端點helloEndpoint連結到系結helloBinding
  • 係結helloBinding是通過HTTP上的SOAP 1.2通訊協定定義的。
  • 係結helloBinding連結到介面helloInterface
  • 介面helloInterface由一個操作Hello定義的,該操作需要輸入訊息元素和輸出訊息元素。
  • 每個元素Hello/HelloResponse都由Types部分中包含的XML模式定義。