日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

WSO2 WSF/CPP--WSDL简介

發布時間:2024/1/1 编程问答 77 豆豆
生活随笔 收集整理的這篇文章主要介紹了 WSO2 WSF/CPP--WSDL简介 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

wsdl(網絡服務描述語言,Web Services Description Language)是一門基于XML的語言,用于描述Web Services以及如何對它進行訪問。

?

wsdl由六個部分組成,都在<definitions>根節點之下

元素

定義

<portType>

Web service的抽象接口,類似于一個在javac#中定義的接口。如果你想快速理解一個web service所提供的功能,看這個部分的內容即可。

<message>

Web service所使用的消息。

<types>

Web service所需要使用到的數據類型,這些數據類型用xml schema元素列表示

<binding>

描述了portType如何被映射到具體的數據格式或協議

<port>

描述服務的端點(endpoint)的部署信息,簡單的說,就是描述了可以找到此服務的url

<service>

是一個port元素的集合,通過它,可以指定一個web service在多個端點上發布

?

一個wsdl文檔的主要結構是類似這樣的:

<definitions>

? <types>

??? definition of types...

? </types>

?

? <message>

??? definition of message...

? </message>

?

? <portType>

??? definition of port...

? </portType>

?

? <binding>

??? definition of binding...

? </binding>

? <service>

??? <port>...</port>

??? <port>...</port>

? </service>

</definitions>

?

1.1 命名空間

命名空間是用于分類和歸類XML文檔中的元素、數據類型以及屬性名的一種方法。XML命名空間類似于javapackagec#namespace關鍵字,用于解決命名沖突。舉例如下

<!--shipping.xsd-->

<complexType name="Address">

<sequence>

<element name="street" type="string" minOccurs="1"/>

<element name="city" type="string" minOccurs="1" maxOccurs="1"/>

<element name="state" type="string" minOccurs="1" maxOccurs="1"/>

<element name="zipCode" type="string" minOccurs="1" maxOccurs="1"/>

</sequence>

</complexType>

?

<!--customer.xsd-->

<complexType name="Address">

<sequence>

<element name="street1" type="string" minOccurs="1" maxOccurs="1"/>

<element name="street2" type="string" minOccurs="1" maxOccurs="1"/>

<element name="street3" type="string" minOccurs="1" maxOccurs="1"/>

<element name="city" type="string" minOccurs="1" maxOccurs="1"/>

<element name="state" type="string" minOccurs="1" maxOccurs="1"/>

<element name="zipCode" type="string" minOccurs="1" maxOccurs="1"/>

</sequence>

</complexType>

?

<!--order.wsdl-->

<?xml version="1.0" encoding="UTF-8"?>

<wsdl:definitions

xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap"

xmlns:tns="http://www.alsb.com/sample"

xmlns:wsdl="http://schemas.xmlsoap.org/wsdl"

xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Sample"

xmlns:shp="http://www.alsb.com/shipping"

xmlns:customer="http://www.alsb.com/customer"

targetNamespace="http://www.alsb.com/order/">

?

<wsdl:types>

<xsd:schema targetNamespace="http://www.alsb.com/customer">

<xsd:element name="CustomerAddress" type="customer:Address"></xsd:element>

<xsd:element name="ShippingAddress" type="shp:Address"></xsd:element>

</xsd:schema>

</wsdl:types>

</wsdl:definitions>

從上面的例子可以看出,為了使“Address”不沖突,引入了命名空間來加以區分。

?

1.2 <types>

wsdl使用xml schema來定義數據類型。Xml schema提供了相當多的本地數據類型(string, integer, date, time...;例如聲明一個string類型的對象,可以這樣做:

<element name="MyString" type="string"/>

?

可以通過本地數據類型來組合自定義一些復雜數據類型,如前一節提到的兩個Address數據類型定義。minOccurs規定一個元素在sequence中出現的最小次數,如果為0表示該元素的出現是可選的;maxOccours是對minOccurs的一個補充,指定元素在sequence中出現的最大次數,maxOccours的值必須大于0,或者設為unbound

?

當需要使用外部定義好的xml schema,需要先導入到當前wsdl文檔中。例如前一節提到的,將shipping.xsdcustomer.xsd導入到order.wsdl中需要如下的語句:

<xs:import namespace="http://www.alsb.com/customer" shcemaLocation="customer.xsd" />

<xs:import namespace="http://www.alsb.com/shipping" shcemaLocation="shipping.xsd" />

?

1.3 <message>

消息(message)描述了輸入、輸出以及錯誤信息的基本形式。消息是由一個或多個<part>元素組成的,這些<part>元素描述了<message>的成分。

<wsdl:message>

<wsdl:part element="tns:getCustomerResponse" name="customer"/>

</wsdl:message>

?

1.4 <portType>

wsdlportType部分描述了web service的抽象接口。在wsdl中,這個部分可以類比為java的抽象接口,因為它從更高層次定義了操控服務的方法(即需要什么參數,以及返回什么結果)。

<portType>元素是由多個<operation>元素組成的。這些<operation>則是由一些對應的<message>元素的<input><output>元素組成。<operation>元素可能包含<fault>元素,以用于顯示操作中可能拋出的soap錯誤。

<wsdl:portType name="CustomerPortType">

<wsdl:operation name="findCustomer">

<wsdl:input message="tns:findCustomer" />

<wsdl:output message="tns:findCustomerResponse"/>

</wsdl:operation>

</wsdl:portType>

?

1.5 <binding>

<binding>用于定義<portType>(web service的抽象接口)如何被綁定到一個傳輸協議和一個編碼(encoding)配置上。一個單獨的<portType>可以被綁定到多個由transportencoding shcema組合配置上。

<wsdl:bingding name="CustomerServiceSoap" type="tns:CustomerPortType">

<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>

<wsdl:operation name="findCustomer">

<soap:operation soapAction="" style="document" />

<wsdl:input>

<soap:body parts="findCustomer" use="literal"/>

</wsdl:input>

<wsdl:output>

<soap:body parts="findCustomerResponse" use="literal" />

</wsdl:output>

</wsdl:operation>

</wsdl:binding>

?

1.6 <service>

一個服務<service>簡單來說就是一組<port>元素的集合。一個wsdl可能包括了多個<service>定義,每一個定義對應web service所支持的不同binding類型。

?

1.7 <port>

<port>描述了binding的物理位置。

<wsdl:service name="CustomerService">

<wsdl:port binding="tns:CustomerServiceSoap" name="CustomerServiceSoap">

<soap:address location="http://server1:7001/customer/CustomerService" />

<soap:address location="http://server2:7001/customer/CustomerService" />

</wsdl:port>

</wsdl:service>

上面的例子顯示了一個web service的例子,它存在于兩個不同的端點上。端點(Endpoint)簡單來說就是一個指向某個服務所在物理位置的URI

?

1.8 兩個完整的例子

<?xml version="1.0" encoding="UTF-8"?>

<!-- hello.wsdl -->

<wsdl:definitions targetNamespace="http://192.168.34.41:9090/axis2/services/hello"

xmlns:apachesoap="http://xml.apache.org/xml-soap"

xmlns:impl="http://192.168.34.41:9090/axis2/services/hello"

xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"

xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"

xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<!-- 定義了兩個數據類型作為greetX的輸入參數和輸出參數 -->

<wsdl:types>

<schema elementFormDefault="qualified"

targetNamespace="http://192.168.34.41:9090/axis2/services/hello"

xmlns="http://www.w3.org/2001/XMLSchema"

xmlns:apachesoap="http://xml.apache.org/xml-soap"

xmlns:impl="http://192.168.34.41:9090/axis2/services/hello"

xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">

<element name="greetRequest">

<complexType>

<sequence>

<element name="greetInput" type="xsd:string" />

</sequence>

</complexType>

</element>

<element name="greetResponse">

<complexType>

<sequence>

<element name="greetReturn" type="xsd:string" />

</sequence>

</complexType>

</element>

</schema>

</wsdl:types>

<!-- 使用上面定義的數據類型,為每一個接口方法定義了輸入輸出消息 -->

<wsdl:message name="greetResponse1">

<wsdl:part element="impl:greetResponse" name="parameters" />

</wsdl:message>

<wsdl:message name="greetRequest1">

<wsdl:part element="impl:greetRequest" name="parameters" />

</wsdl:message>

<wsdl:message name="greetResponse2">

<wsdl:part element="impl:greetResponse" name="parameters" />

</wsdl:message>

<wsdl:message name="greetRequest2">

<wsdl:part element="impl:greetRequest" name="parameters" />

</wsdl:message>

<wsdl:message name="greetResponse3">

<wsdl:part element="impl:greetResponse" name="parameters" />

</wsdl:message>

<wsdl:message name="greetRequest3">

<wsdl:part element="impl:greetRequest" name="parameters" />

</wsdl:message>

<!-- 定義接口,指定接口名稱、使用的輸入輸出消息 -->

<wsdl:portType name="hello">

<wsdl:operation name="greet1">

<wsdl:input message="impl:greetRequest1" name="greetRequest1" />

<wsdl:output message="impl:greetResponse1" name="greetResponse1" />

</wsdl:operation>

<wsdl:operation name="greet2">

<wsdl:input message="impl:greetRequest2" name="greetRequest2" />

<wsdl:output message="impl:greetResponse2" name="greetResponse2" />

</wsdl:operation>

<wsdl:operation name="greet3">

<wsdl:input message="impl:greetRequest3" name="greetRequest3" />

<wsdl:output message="impl:greetResponse3" name="greetResponse3" />

</wsdl:operation>

</wsdl:portType>

<!-- 指定傳輸協議和編碼 -->

<wsdl:binding name="HelloSoapBinding" type="impl:hello">

<wsdlsoap:binding style="document"

transport="http://schemas.xmlsoap.org/soap/http" />

<wsdl:operation name="greet1">

<wsdlsoap:operation soapAction="hello#greet1" />

<wsdl:input name="greetRequest1">

<wsdlsoap:body use="literal" />

</wsdl:input>

<wsdl:output name="greetResponse1">

<wsdlsoap:body use="literal" />

</wsdl:output>

</wsdl:operation>

<wsdl:operation name="greet2">

<wsdlsoap:operation soapAction="hello#greet2" />

<wsdl:input name="greetRequest2">

<wsdlsoap:body use="literal" />

</wsdl:input>

<wsdl:output name="greetResponse2">

<wsdlsoap:body use="literal" />

</wsdl:output>

</wsdl:operation>

<wsdl:operation name="greet3">

<wsdlsoap:operation soapAction="hello#greet3" />

<wsdl:input name="greetRequest3">

<wsdlsoap:body use="literal" />

</wsdl:input>

<wsdl:output name="greetResponse3">

<wsdlsoap:body use="literal" />

</wsdl:output>

</wsdl:operation>

</wsdl:binding>

<!-- 定義服務 -->

<wsdl:service name="hello">

<wsdl:port binding="impl:HelloSoapBinding" name="hello">

<wsdlsoap:address location="http://192.168.34.41:9090/axis2/services/hello" />

</wsdl:port>

</wsdl:service>

</wsdl:definitions>

?

?

<?xml version="1.0" encoding="UTF-8"?>

<!-- PersonInfoService.wsdl -->

<wsdl:definitions

? xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"

? xmlns:ns1="http://org.apache.axis2/xsd"

? xmlns:ns="http://samples.esb.wso2.org"

? xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"

? xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"

? xmlns:ax21="http://samples.esb.wso2.org/xsd"

? xmlns:xs="http://www.w3.org/2001/XMLSchema"

? xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"

? xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"

? xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"

? targetNamespace="http://samples.esb.wso2.org">

? <wsdl:documentation>PersonInfoService</wsdl:documentation>

? <wsdl:types>

??? <xs:schema xmlns:ax22="http://samples.esb.wso2.org/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://samples.esb.wso2.org">

????? <xs:import namespace="http://samples.esb.wso2.org/xsd" />

????? <xs:element name="get">

??????? <xs:complexType>

????????? <xs:sequence>

??????????? <xs:element minOccurs="0" name="id" nillable="true" type="xs:string" />

????????? </xs:sequence>

??????? </xs:complexType>

????? </xs:element>

????? <xs:element name="getResponse">

??????? <xs:complexType>

????????? <xs:sequence>

??????????? <xs:element minOccurs="0" name="return" nillable="true" type="ax21:PersonInfo" />

????????? </xs:sequence>

??????? </xs:complexType>

????? </xs:element>

??? </xs:schema>

??? <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://samples.esb.wso2.org/xsd">

????? <xs:complexType name="PersonInfo">

??????? <xs:sequence>

????????? <xs:element minOccurs="0" name="address" nillable="true" type="xs:string" />

????????? <xs:element minOccurs="0" name="id" nillable="true" type="xs:string" />

????????? <xs:element minOccurs="0" name="name" nillable="true" type="xs:string" />

??????? </xs:sequence>

????? </xs:complexType>

??? </xs:schema>

? </wsdl:types>

? <wsdl:message name="getRequest">

??? <wsdl:part name="parameters" element="ns:get" />

? </wsdl:message>

? <wsdl:message name="getResponse">

??? <wsdl:part name="parameters" element="ns:getResponse" />

? </wsdl:message>

? <wsdl:portType name="PersonInfoServicePortType">

??? <wsdl:operation name="get">

????? <wsdl:input message="ns:getRequest" wsaw:Action="urn:get" />

????? <wsdl:output message="ns:getResponse" wsaw:Action="urn:getResponse" />

??? </wsdl:operation>

? </wsdl:portType>

? <wsdl:binding name="PersonInfoServiceSoap11Binding" type="ns:PersonInfoServicePortType">

??? <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />

??? <wsdl:operation name="get">

????? <soap:operation soapAction="urn:get" style="document" />

????? <wsdl:input>

??????? <soap:body use="literal" />

????? </wsdl:input>

????? <wsdl:output>

??????? <soap:body use="literal" />

????? </wsdl:output>

??? </wsdl:operation>

? </wsdl:binding>

? <wsdl:binding name="PersonInfoServiceSoap12Binding" type="ns:PersonInfoServicePortType">

??? <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />

??? <wsdl:operation name="get">

????? <soap12:operation soapAction="urn:get" style="document" />

????? <wsdl:input>

??????? <soap12:body use="literal" />

????? </wsdl:input>

????? <wsdl:output>

??????? <soap12:body use="literal" />

????? </wsdl:output>

??? </wsdl:operation>

? </wsdl:binding>

? <wsdl:binding name="PersonInfoServiceHttpBinding" type="ns:PersonInfoServicePortType">

??? <http:binding verb="POST" />

??? <wsdl:operation name="get">

????? <http:operation location="get" />

????? <wsdl:input>

??????? <mime:content type="text/xml" part="parameters" />

????? </wsdl:input>

????? <wsdl:output>

??????? <mime:content type="text/xml" part="parameters" />

????? </wsdl:output>

??? </wsdl:operation>

? </wsdl:binding>

? <wsdl:service name="PersonInfoService">

??? <wsdl:port name="PersonInfoServiceHttpsSoap11Endpoint" binding="ns:PersonInfoServiceSoap11Binding">

????? <soap:address location="https://10.215.26.81:9443/services/PersonInfoService.PersonInfoServiceHttpsSoap11Endpoint/" />

??? </wsdl:port>

??? <wsdl:port name="PersonInfoServiceHttpSoap11Endpoint" binding="ns:PersonInfoServiceSoap11Binding">

????? <soap:address location="http://10.215.26.81:9763/services/PersonInfoService.PersonInfoServiceHttpSoap11Endpoint/" />

??? </wsdl:port>

??? <wsdl:port name="PersonInfoServiceHttpSoap12Endpoint" binding="ns:PersonInfoServiceSoap12Binding">

????? <soap12:address location="http://10.215.26.81:9763/services/PersonInfoService.PersonInfoServiceHttpSoap12Endpoint/" />

??? </wsdl:port>

??? <wsdl:port name="PersonInfoServiceHttpsSoap12Endpoint" binding="ns:PersonInfoServiceSoap12Binding">

????? <soap12:address location="https://10.215.26.81:9443/services/PersonInfoService.PersonInfoServiceHttpsSoap12Endpoint/" />

??? </wsdl:port>

??? <wsdl:port name="PersonInfoServiceHttpsEndpoint" binding="ns:PersonInfoServiceHttpBinding">

????? <http:address location="https://10.215.26.81:9443/services/PersonInfoService.PersonInfoServiceHttpsEndpoint/" />

??? </wsdl:port>

??? <wsdl:port name="PersonInfoServiceHttpEndpoint" binding="ns:PersonInfoServiceHttpBinding">

????? <http:address location="http://10.215.26.81:9763/services/PersonInfoService.PersonInfoServiceHttpEndpoint/" />

??? </wsdl:port>

? </wsdl:service>

</wsdl:definitions>

?

轉載于:https://www.cnblogs.com/seamancode/archive/2011/07/29/wsdl.html

總結

以上是生活随笔為你收集整理的WSO2 WSF/CPP--WSDL简介的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。