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 - greeting 返回值

  • 埠型別 - sayHello 操作由請求和響應服務組成。

  • 繫結 - 使用 SOAP HTTP 傳輸協議的指令。

  • 服務 - 可在 http://www.examples.com/SayHello/ 處獲得的服務

  • - 將繫結與可訪問正在執行的服務的 URI http://www.examples.com/SayHello/ 相關聯。

廣告
© . All rights reserved.