標籤:city tty services 應用程式 oct multipart pos rtt 通訊
WebService(jax-ws)三要素 SOAP: 基於HTTP協議,採用XML格式,用來傳遞資訊的格式。 WSDL: 用來描述如何訪問具體的服務。(相當於說明書) UDDI: 使用者自己可以按UDDI標準搭建UDDI伺服器,用來管理,分發,查詢WebService 。其他使用者可以自己註冊發布WebService調用。(現在基本廢棄) 1.SOAP(通訊協議) Simple Object Accrss Protocol,簡易物件存取通訊協定 (SOAP)是在分散或分布式的環境中交換資訊的簡單的協議,是一個基於XML的協議,它包括四個部分:(1)SOAP封裝(envelop),封裝定義了一個描述訊息中的內容是什麼,是誰發送的,誰應當接受並處理它,以及如何處理它們的架構;(2)SOAP編碼規則,用於表示應用程式需要使用的資料類型的執行個體。(2)SOAP RPC 表示遠端程序呼叫和應答的協定。(4)SOAP綁定(binding),使用底層協議交換資訊。 (1)請求的協議體POST /weather HTTP/1.1Accept: text/xml, multipart/relatedContent-Type: text/xml; charset=utf-8SOAPAction: "http://weather.itheima.com/WeatherInterface/getWeatherByCityNameRequest"User-Agent: JAX-WS RI 2.2.4-b01Host: 127.0.0.1:54321Connection: keep-aliveContent-Length: 235<?xml version="1.0" ?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Body> <ns2:getWeatherByCityName xmlns:ns2="http://weather.itheima.com"> <cityName>北京</cityName> </ns2:getWeatherByCityName> </S:Body></S:Envelope> (2)響應的協議體HTTP/1.1 200 OKTransfer-encoding: chunkedContent-type: text/xml; charset=utf-8Date: Fri, 09 Oct 2015 07:23:29 GMT<?xml version="1.0" ?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Body> <ns2:getWeatherByCityNameResponse xmlns:ns2="http://weather.itheima.com"> <WeatherInfo>今天風很大</WeatherInfo> </ns2:getWeatherByCityNameResponse> </S:Body></S:Envelope> (3)發布基於soap1.2協議的服務在SEI(service endpoint interface 服務端點介面)實作類別上添加如下註解@BindingType(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)發布基於soap1.2協議的服務,需要jax-ws包要求2.2.8以上版本。 (4)soap1.2請求的協議體POST /weather HTTP/1.1Accept: application/soap+xml, multipart/relatedContent-Type: application/soap+xml; charset=utf-8;action="http://weather.itheima.com/WeatherInterface/getWeatherByCityNameRequest"User-Agent: JAX-WS RI 2.2.4-b01Host: 127.0.0.1:54321Connection: keep-aliveContent-Length: 233<?xml version="1.0" ?><S:Envelope xmlns:S="http://www.w3.org/2003/05/soap-envelope"> <S:Body> <ns2:getWeatherByCityName xmlns:ns2="http://weather.itheima.com"> <cityName>北京</cityName> </ns2:getWeatherByCityName> </S:Body></S:Envelope> (5)soap1.2響應的協議體HTTP/1.1 200 OKTransfer-encoding: chunkedContent-type: application/soap+xml; charset=utf-8Date: Fri, 09 Oct 2015 07:54:53 GMT<?xml version=‘1.0‘ encoding=‘UTF-8‘?><S:Envelope xmlns:S="http://www.w3.org/2003/05/soap-envelope"> <S:Body> <ns2:getWeatherByCityNameResponse xmlns:ns2="http://weather.itheima.com"> <WeatherInfo>今天風很大</WeatherInfo> </ns2:getWeatherByCityNameResponse> </S:Body></S:Envelope> 2.WSDL WSDL(Web Service Description Language),是一個用來描述Web服務(Web Service)和說明如何與Web服務通訊的XML語言。因為是基於XML的,
所以WSDL既是機器可閱讀的,又是人可閱讀的,這將是一個很大的好處。
(1)wsdl的閱讀方法是從下往上讀。每個wsdl有且只有一個Service節點。1、先找Service節點2、Service節點中找port節點。每個port對應一個PortType。3、Port節點對應一binding節點。每個binding節點對應一個PortType4、PortType中有operation 節點就是服務的方法。5、operation 中有Input(參數)和output(傳回值)6、Input(參數)和output(傳回值)對應message節點7、Message對應element節點。Element節點對應complexType節點描述了參數及傳回值的資料類型。 (2)使用註解規範wsdl@WebService: 定義服務,在public class上邊。 targetNamespace:指定命名空間。 name:portType的名稱。 portName:port的名稱。 serviceName:服務名稱。 @WebResult:定義傳回值。 name:返回結果值的名稱。 @WebParam:定義參數。 name:指定參數的名稱。 @WebMethodexclude:排除指定的方法。預設情況下,SEI實作類別中所以的public方法會發布成服務方法。如果不想把public方法發布成服務方法,需要使用@WebMethod註解。把此方法排除。在實作類別中至少有一個方法發布為服務方法。
http://127.0.0.1:12345/weather?wsdl
http://127.0.0.1:12345/weather?xsd=1
作用: 通過註解,可以更加形像的描述Web服務。對自動產生的wsdl文檔進行修改,為使用者提供一個更加清晰的wsdl文檔。當修改了WebService註解之後,會影響用戶端產生的程式碼。調用的方法名和參數名也發生了變化。 3.UDDI UDDI 是一種目錄服務,通過它,企業可註冊並搜尋 Web services。企業將自己提供的Web Service註冊在UDDI,也可以使用別的企業在UDDI註冊的web service服務,從而達到資源共用。 UDDI旨在將全球的webservcie資源進行共用,促進全球經濟合作。 但是使用webservice並不是必須使用UDDI,因為使用者通過WSDL知道了web service的地址,可以直接通過WSDL調用webservice。(現已廢棄)
webService 三要素