WSDL範例


下面給出了一個WSDL檔案,用於演示簡單的WSDL程式。

假設這個服務提供了一個名稱為sayHello的公共可用函式。 此函式需要單個字串引數並返回單個字串問候語。 例如,如果傳遞引數值為:"world",那麼服務函式sayHello將返回問候語:"Hello,world!"

範例

HelloService.wsdl 檔案的內容如下所示 -

<definitions name = "HelloService"
   targetNamespace = "http://www.examples.com/wsdl/HelloService.wsdl"
   xmlns = "http://schemas.xmlsoap.org/wsdl/"
   xmlns:soap = "http://schemas.xmlsoap.org/wsdl/soap/"
   xmlns:tns = "http://www.examples.com/wsdl/HelloService.wsdl"
   xmlns:xsd = "http://www.w3.org/2001/XMLSchema">

   <message name = "SayHelloRequest">
      <part name = "firstName" type = "xsd:string"/>
   </message>

   <message name = "SayHelloResponse">
      <part name = "greeting" type = "xsd:string"/>
   </message>

   <portType name = "Hello_PortType">
      <operation name = "sayHello">
         <input message = "tns:SayHelloRequest"/>
         <output message = "tns:SayHelloResponse"/>
      </operation>
   </portType>

   <binding name = "Hello_Binding" type = "tns:Hello_PortType">
      <soap:binding style = "rpc"
         transport = "http://schemas.xmlsoap.org/soap/http"/>
      <operation name = "sayHello">
         <soap:operation soapAction = "sayHello"/>
         <input>
            <soap:body
               encodingStyle = "http://schemas.xmlsoap.org/soap/encoding/"
               namespace = "urn:examples:helloservice"
               use = "encoded"/>
         </input>

         <output>
            <soap:body
               encodingStyle = "http://schemas.xmlsoap.org/soap/encoding/"
               namespace = "urn:examples:helloservice"
               use = "encoded"/>
         </output>
      </operation>
   </binding>

   <service name = "Hello_Service">
      <documentation>WSDL File for HelloService</documentation>
      <port binding = "tns:Hello_Binding" name = "Hello_Port">
         <soap:address
            location = "http://www.examples.com/SayHello/" />
      </port>
   </service>
</definitions>

範例分析說明

  • 定義 - HelloService
  • 型別 - 使用內建資料型別,它們在XMLSchema中定義。
  • 訊息 -
    • sayHelloRequest - firstName引數
    • sayHelloresponse - 問候的返回值
  • 埠型別 - 由請求和響應服務組成的sayHello操作。
  • 係結 - 使用SOAP HTTP傳輸協定的方向。
  • 服務 - 可從 http://www.examples.com/SayHello/ 獲取服務
  • - 將系結與URI => http://www.examples.com/SayHello/ 相關聯,可以存取正在執行的服務。