Web Service:MS在2000年創(chuàng )造了Web Service這個(gè)詞,它描述的是允許計算機網(wǎng)絡(luò )(互聯(lián)網(wǎng)是典型,但不局限與此)相互通信的一套標準,其核心之一是可擴展標記語(yǔ)言(XML),另一個(gè)則是HTTP。
5個(gè)基礎標準(其中有兩個(gè)是早就有了的通用標準,他們被用來(lái)實(shí)現Web Service方法,另外3個(gè)是專(zhuān)門(mén)用于Web Service的):
1. XML 用來(lái)描述模型,格式和數據類(lèi)型的通用格式,其他大多數標準都是用XML來(lái)表達的標準。
2. HTTP(HTTPS),互聯(lián)網(wǎng)底層協(xié)議。HTTP(S)是運用了互聯(lián)網(wǎng)技術(shù),通過(guò)網(wǎng)絡(luò )發(fā)送Web Service的可能的協(xié)議之一。
3. WSDL(Web Services Description Language):用來(lái)定義服務(wù)接口。描述服務(wù)的兩個(gè)方面:服務(wù)的簽名(名字和參數),以及服務(wù)的綁定和部署細節(協(xié)議和位置)。
4. SOAP是Web Service交換數據所準尋的協(xié)議。
5. UDDI,管理Web Service的標準(注冊和找到服務(wù))
通常來(lái)說(shuō),使用WSDL標準是Web Service的關(guān)鍵特性,其他都是可選的。例如,不一定非得使用SOAP和HTTP萊發(fā)送服務(wù)請求,也可以使用其他協(xié)議而仍然算在使用Web Service。另外,UDDI扮演補充的角色,實(shí)際中也不用。
WSDL:
怎樣向別人介紹你的Web service有什么功能,以及每個(gè)函數調用時(shí)的參數呢?這就是WSDL。 WSDL標準有不同的版本,主要講WSDL1.1和WSDL2.0。相比較于1.1,2.0主要有:

WSDL文件自底向上描述服務(wù)。也就是說(shuō),它們從用到的數據類(lèi)型開(kāi)始,道服務(wù)的位置(地址)結束。
<?xml version="1.0" encoding="utf-8" ?>
2 <definitions name="CustomerService"
3 targetNamespace="http://soa-in-practice.com/wsdl"
4 xmlns:tns="http://soa-in-practice.com/wsdl"
5 xmlns:xsd1="http://soa-in-practice.com/xsd"
6 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
7 xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
8 xmlns="http://schemas.xmlsoap.org/wsdl/">
9
10 <types>
11 <xsd:schema
12 targetNamespace="http://soa-in-practice.com/xsd"
13 xmlns="http://soa-in-practice.com/xsd">
14
15 <xsd:element name="getCustomerAddress">
16 <xsd:complexType>
17 <xsd:sequence>
18 <xsd:element name="customerID" type="xsd:long"/>
19 </xsd:sequence>
20 </xsd:complexType>
21 </xsd:element>
22
23 <xsd:element name="getCustomerAddressResponse" type="Address"/>
24 <xsd:complexType name="Address">
25 <xsd:sequence>
26 <xsd:element name="street" type="xsd:string"/>
27 <xsd:element name="city" type="xsd:string"/>
28 <xsd:element name="zipCode" type="xsd:string"/>
29 </xsd:sequence>
30 </xsd:complexType>
31
32 </xsd:schema>
33 </types>
34
35 <message name="getCustomerAddressInput">
36 <part name="params" element="xsd1:getCustomerAddress"/>
37 </message>
38 <message name="getCustomerAddressOutput">
39 <part name="params" element="xsd1:getCustomerAddressResponse"/>
40 </message>
41
42 <portType name="CustomerInterface" >
43 <operation name="getCustomerAddress">
44 <input message="tns:getCustomerAddressInput" name=" getCustomerAddressInput"/>
45 <output message="tns:getCustomerAddressOutput" name=" getCustomerAddressOutput "/>
46 </operation>
47 </portType>
48
49 <binding name="CustomerSOAPBinding"
50 type="tns:CustomerInterface" >
51 <soap:binding style="document"
52 transport="http://schemas.xmlsoap.org/soap/http" />
53 <operation name="getCustomerAddress">
54 <soap:operation
55 soapAction="http://soa-in-practice.com/getCustomerAddress" />
56 <input name=" getCustomerAddressInput ">
57 <soap:body use="literal" />
58 </input>
59 <output name=" getCustomerAddressOutput ">
60 <soap:body use="literal" />
61 </output>
62 </operation>
63 </binding>
64
65 <service name="CustomerService" >
66 <port name="CustomerPort"
67 binding="tns:CustomerSOAPBinding">
68 <soap:address
69 location="http://soa-in-practice.com/customer11"/>
70 </port>
71 </service>
72
73 </definitions>
l 最后的service定義了一個(gè)名為CustomerService的服務(wù),該服務(wù)可以從http://soa-in-practice.com/customer11得到,與其一同提供的有被稱(chēng)為CustomerSOAPBinding的綁定。前綴tns是可以找到這個(gè)綁定標示符細節的命名空間,可以在最前面找到。
l Binding定義了用來(lái)提供服務(wù)的協(xié)議和格式。這里我們可以看到CustomerSOAPBinding的定義。指定用于CustomerInterface的接口類(lèi)型。這個(gè)綁定是基于底層HTTP協(xié)議的SOAP綁定,這里的風(fēng)格為document/ literal
l portType定義了接口CustomerInterface的接口。它包含一個(gè)叫getCustomerAddress的操作,指明了當操作被調用時(shí)候,服務(wù)總線(xiàn)發(fā)送的消息。它發(fā)送一個(gè)請求,收到一個(gè)應答(牽涉到消息交換格式)。這通過(guò)一個(gè)輸入消息getCustomerAddressInput,以及一個(gè)輸出消息getCustomerAddressOutput來(lái)定義。
l message定義了各個(gè)消息,使用的是portType節引用的標示符。不管是getCustomerAddressInput還是getCustomerAddressOutput,都是用了在<types>節中定義的數據類(lèi)型。
l types定義了將會(huì )使用的數據類(lèi)型:輸入參數customerID的類(lèi)型是long,輸出參數address的類(lèi)型是有3個(gè)字符串屬性的結構記錄。所有類(lèi)型在自己的命名空間wsdl中。
版本2.0對應的WSDL文件:
1 <?xml version="1.0" encoding="utf-8" ?>
2 <description
3 targetNamespace="http://soa-in-practice.com/wsdl"
4 xmlns:tns="http://soa-in-practice.com/wsdl"
5 xmlns:xsd1="http://soa-in-practice.com/xsd"
6 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
7 xmlns:wsoap="http://www.w3.org/2006/01/wsdl/soap"
8 xmlns:wsdlx="http://www.w3.org/2006/01/wsdl-extensions"
9 xmlns="http://www.w3.org/2006/01/wsdl">
10
11 <types>
12 <xsd:schema
13 targetNamespace="http://soa-in-practice.com/xsd"
14 xmlns="http://soa-in-practice.com/xsd">
15
16 <xsd:element name="getCustomerAddress">
17 <xsd:complexType>
18 <xsd:sequence>
19 <xsd:element name="customerID" type="xsd:long"/>
20 </xsd:sequence>
21 </xsd:complexType>
22 </xsd:element>
23
24 <xsd:element name="getCustomerAddressResponse" type="Address"/>
25 <xsd:complexType name="Address">
26 <xsd:sequence>
27 <xsd:element name="street" type="xsd:string"/>
28 <xsd:element name="city" type="xsd:string"/>
29 <xsd:element name="zipCode" type="xsd:string"/>
30 </xsd:sequence>
31 </xsd:complexType>
32
33 </xsd:schema>
34 </types>
35
36 <interface name = "CustomerInterface" >
37
38 <operation name="getCustomerAddress"
39 pattern="http://www.w3.org/2006/01/wsdl/in-out"
40 style="http://www.w3.org/2006/01/wsdl/style/iri"
41 wsdlx:safe = "true">
42 <input messageLabel="In"
43 element="xsd1:getCustomerAddress" />
44 <output messageLabel="Out"
45 element="xsd1:getCustomerAddressResponse" />
46 </operation>
47
48 </interface>
49
50 <binding name="CustomerSOAPBinding"
51 interface="tns:CustomerInterface"
52 type="http://www.w3.org/2006/01/wsdl/soap"
53 wsoap:protocol="http://www.w3.org/2003/05/soap/bindings/HTTP">
54
55 <operation ref="tns:getCustomerAddress"
56 wsoap:mep="http://www.w3.org/2003/05/soap/mep/soap-response"/>
57
58 </binding>
59
60 <service name="CustomerService"
61 interface="tns:CustomerInterface">
62
63 <endpoint name="CustomerEndpoint"
64 binding="tns:CustomerSOAPBinding"
65 address="http://soa-in-practice.com/customer20"/>
66
67 </service>
68
69 </description>
主要區別是:
1. XML跟元素的名字是description
2. service節是用的是endpoint而非port
3. 在binding節內,定義了SOAP1.2
4. portType被interface取代,是用了根具體,定義了底層消息順序的消息交換模式
5. message節點(diǎn)沒(méi)有了,操作世界引用數據類(lèi)型,定義在types中,發(fā)送那個(gè)消息遵循interface節中指定的類(lèi)型和消息交換模式
6. 用不同的命名空間來(lái)標識WSDL2.0和SOAP1.2
SOAP
SOAP最初是“簡(jiǎn)單對象訪(fǎng)問(wèn)協(xié)議”的首字母縮寫(xiě)詞,后來(lái)開(kāi)發(fā)者發(fā)現SOAP既不簡(jiǎn)單,也不處理對象訪(fǎng)問(wèn),從1.2版本開(kāi)始,這個(gè)縮寫(xiě)詞就被當做一個(gè)詞使用,不再代表一種縮寫(xiě)了。
根據上面的例子。其SOAP請求的一個(gè)例子,如下:
<?xml version='1.0' ?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
...
</soap:Header>
<soap:Body>
<getCustomerAddress xmlns="http://soa-in-practice.com/xsd">
<customerID>12345678</customerID>
</getCustomerAddress >
</soap:Body>
</soap:Envelope>
一個(gè)相應的應答消息如下:
<?xml version='1.0' ?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
...
</soap:Header>
<soap:Body>
<getCustomerAddressResponse xmlns="http://soa-in-practice.com/xsd">
<address>
<street>Gaussstr. 29</street>
<city>Braunschweig</city>
<zipCode>D-38106</zipCode>
</address>
</getCustomerAddressResponse>
</soap:Body>
</soap:Envelope>
可以看到,SOAP消息格式為XML,包含一個(gè)被稱(chēng)為Envelope的跟元素。跟元素包含一個(gè)可選的Header和必備的Body元素。Body元素包含有效載荷(請求、回復、或者錯誤數據),Header包含額外的,幫助基礎設施處理消息的信息(如路由提示,安全提示等)。
UDDI
“通用描述,發(fā)現和集成UDDI”最初是更寬泛的術(shù)語(yǔ),“通用描述、發(fā)現和集成業(yè)務(wù)注冊中心”。最初的想法是,引入一個(gè)有效的市場(chǎng)包含的全部3個(gè)角色:提供服務(wù)的供應者,需要服務(wù)的消費者,以及通過(guò)廣告和定位服務(wù)的兩方撮合道一起的中間人。這就產(chǎn)生了解釋Web Services通常要展示的著(zhù)名三角形:

Web Service其他相關(guān)的標準:
Web Service的第一個(gè)問(wèn)題是,它不是一個(gè)由單個(gè)組織定義的標準。由超過(guò)50個(gè)不同的Web Service規范,分別由三家不同的標準化組織制定,W
即時(shí)對于前面的5個(gè)基礎標準,一直以來(lái),達到互操作性的目標也很困難。即時(shí)選擇了同一版本,規范也太粗糙,太寬泛。于是,在2002年,WS互操作性組織(WS-I)成立。
WS-I的一樣重要東西就是“配套資料”,它是一套已經(jīng)定義了的標準,每一個(gè)標準都制定了特定的版本。
總結:
l Web Service是SOA基礎設施(ESB)事實(shí)上的標準
l 基于XML和HTTP這兩個(gè)協(xié)議,最重要的是用于描述Web Service接口的WSDL,以及用于規定Web Service通信協(xié)議格式的SOAP。
l WSDL文件將不同的層用于服務(wù)接口,綁定和部署細節,因此,通常需要適當的過(guò)程來(lái)處理WSDL文件的生命周期。
l WSDL并沒(méi)有綁定在SOAP上,可以使用其他綁定,所以接口描述在原則上能和任何技術(shù)一起使用
l 作為一個(gè)標準,WSDL只定義了互操作性的核心特性,沒(méi)有提供按去啊你選哪個(gè)、SLA等附加特性,這些也行可以由其他標準提供。
l 不同的標準化組織規定可許多不同的Web Service標準,各標準也有許多不同的版本,因此,互操作成為一個(gè)問(wèn)題。Web Service互操作性組織(WS-I)試圖解決這個(gè)問(wèn)題,其方法為針對某些標準的集合提供各種配套資料
l 在實(shí)踐中,為了互操作,通常應該使用WS-I基本配套資料和SOAP document/literal wrapped綁定
聯(lián)系客服