1. 程式人生 > >webservice 教程學習系列(八)——wsdl文件深入分析

webservice 教程學習系列(八)——wsdl文件深入分析

首先上一下 sayHello.wsdl的原始碼

<?xml version="1.0" encoding="UTF-8"?><!-- Published by JAX-WS RI (http://jax-ws.java.net). 
	RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. --><!-- Generated by JAX-WS RI (http://jax-ws.java.net). 
	RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. -->
<definitions
	xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
	xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy"
	xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
	xmlns:tns="http://ws/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
	xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://ws/"
	name="HelloWSImplService">
	<types>
		<xsd:schema>
			<xsd:import namespace="http://ws/"
				schemaLocation="http://192.168.199.215:8989/ws_test/zq?xsd=1"></xsd:import>
		</xsd:schema>
	</types>
	<message name="sayHello">
		<part name="parameters" element="tns:sayHello"></part>
	</message>
	<message name="sayHelloResponse">
		<part name="parameters" element="tns:sayHelloResponse"></part>
	</message>
	<portType name="HelloWSImpl">
		<operation name="sayHello">
			<input wsam:Action="http://ws/HelloWSImpl/sayHelloRequest"
				message="tns:sayHello"></input>
			<output wsam:Action="http://ws/HelloWSImpl/sayHelloResponse"
				message="tns:sayHelloResponse"></output>
		</operation>
	</portType>
	<binding name="HelloWSImplPortBinding" type="tns:HelloWSImpl">
		<soap:binding transport="http://schemas.xmlsoap.org/soap/http"
			style="document"></soap:binding>
		<operation name="sayHello">
			<soap:operation soapAction=""></soap:operation>
			<input>
				<soap:body use="literal"></soap:body>
			</input>
			<output>
				<soap:body use="literal"></soap:body>
			</output>
		</operation>
	</binding>
	<service name="HelloWSImplService">
		<port name="HelloWSImplPort" binding="tns:HelloWSImplPortBinding">
			<soap:address location="http://192.168.199.215:8989/ws_test/zq"></soap:address>
		</port>
	</service>
</definitions>

(1)   types

 <types>
        <xsd:schema>
            <xsd:import namespace="http://ws/"
                schemaLocation="http://192.168.199.215:8989/ws_test/zq?xsd=1"></xsd:import>
        </xsd:schema>
    </types>

在瀏覽器中輸入:http://192.168.199.215:8989/ws_test/zq?xsd=1

可以看到其檔案約束

  <?xml version="1.0" encoding="UTF-8"?><!-- Published by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. --><xs:schema xmlns:tns="http://ws/" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0" targetNamespace="http://ws/">
   
  <xs:element name="sayHello" type="tns:sayHello"></xs:element>
   
  <xs:element name="sayHelloResponse" type="tns:sayHelloResponse"></xs:element>
   
  <xs:complexType name="sayHello">
  <xs:sequence>
  <xs:element name="arg0" type="xs:string" minOccurs="0"></xs:element>
  </xs:sequence>
  </xs:complexType>
   
  <xs:complexType name="sayHelloResponse">
  <xs:sequence>
  <xs:element name="return" type="xs:string" minOccurs="0"></xs:element>
  </xs:sequence>
  </xs:complexType>
  </xs:schema>

這個主要是約束了請求和響應的xml格式:

這個用於約束請求

<sayHello>

<arg0>string</arg0>

</sayHello>

這個用於約束響應

<sayHelloResponse>

<arg0>string</arg0>

</sayHelloResponse>

(2)message

<message name="sayHello">
        <part name="parameters" element="tns:sayHello"></part>
    </message>
    <message name="sayHelloResponse">
        <part name="parameters" element="tns:sayHelloResponse"></part>
    </message>

message:用來定義訊息的結構:一共就兩個訊息,一個請求訊息,一個響應訊息;

part:用來定義指定引用types中定義的標籤片段;

(3)portType

 

   <portType name="HelloWSImpl">
        <operation name="sayHello">
            <input wsam:Action="http://ws/HelloWSImpl/sayHelloRequest"
                message="tns:sayHello"></input>
            <output wsam:Action="http://ws/HelloWSImpl/sayHelloResponse"
                message="tns:sayHelloResponse"></output>
        </operation>
    </portType>

portType 用來定義伺服器的SEI;

operation :用來定義SEI中處理請求的方法;

input:指定客戶端應用傳過來的資料,會引用上面的message;

output:是指伺服器端返回給客戶端的資料,會引用上面的message;

(4)binding

<binding name="HelloWSImplPortBinding" type="tns:HelloWSImpl">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http"
            style="document"></soap:binding>
        <operation name="sayHello">
            <soap:operation soapAction=""></soap:operation>
            <input>
                <soap:body use="literal"></soap:body>
            </input>
            <output>
                <soap:body use="literal"></soap:body>
            </output>
        </operation>
    </binding>

binding :用於定義SEI的實現類;

type:醫用上面定義的portType標籤;

operation :方法的具體實現;

    <soap:binding transport="http://schemas.xmlsoap.org/soap/http"
            style="document"></soap:binding>:用來指定使用xml文件傳輸

<soap:body use="literal"></soap:body>:是指客戶端傳過來的資料是文字資料

(5)service

<service name="HelloWSImplService">
        <port name="HelloWSImplPort" binding="tns:HelloWSImplPortBinding">
            <soap:address location="http://192.168.199.215:8989/ws_test/zq"></soap:address>
        </port>
    </service>

service :是伺服器端的一個webservice容器

name屬性:用來指定客戶端容器類;

port:用來指定一個伺服器端處理請求的入口,其實就是對應一個service服務的入口。

binding屬性:引用上面的binding標籤;

address:當前webservice的請求地址。

整體結構提如下所示: