You are on page 1of 21

WEB SERVICES WSDL v CI T

Sinh vin: Bi Hong c Trn Tun Anh on Vit Dng Phm Hong Tin Ging vin: TS. V Th Hng Giang

WSDL and WADL


WSDL: 1.1(2003), 2.0(2007)
2.0: cho RESTful Web services. Theo kho st 32 web service ngu nhin trn xmethods.com, tt c u s dng WSDL 1.1

WADL: for RESTful web service.


Khng c ph bin c bit sau WSDL 2.0. (http://en.wikipedia.org/wiki/Web_Application_De scription_Language)

Cu trc chung ca mt vn bn WSDL


Document element l <definitions>, cc attribute quan trng:
name: tn ca web service. xmlns : namespace ca vn bn WSDL.
WSDL 1.1: http://schemas.xmlsoap.org/wsdl/ WSDL 2.0: http://www.w3.org/ns/wsdl

<definitions> l cc nhm nh ngha, gm 4 phn chnh

Cu trc ca 1 vn bn WSDL

<types>
<types>: optional, cung cp nh ngha cc kiu d liu c s dng cc thng ip. Cc nh ngha kiu d liu thng c vit trong h thng XSD(extensible schema definition).

V d <types>
S dng 1 XSD bn ngoi <types> <xsd:schema> <xsd:import namespace="http://eg/" schemaLocation="HelloService_schema1.xsd" /> </xsd:schema> </types> Nu khng c kiu no c nh ngha trong type: <types />

<message>
nh ngha cc thng ip s dng trong web service. Th t ca cc message phn nh cch hot ng ca web service: request/response hay solicit/response. Tn ca cc message c dng ---In/---Out; --Request/---Response vi --- phn nh operation lin kt vi message.

<portType>
biu din dch v nh l mt tp named operation, mi operation c m t bi cc input/output message . N ging nh l mt interface trong ngn ng Java: cho bit cc operation v message nhng khng cho bit ci t bn trong. <portType> {<operation> <input message=...> <output message=...> </operation>} </portType> Phn ... l mt datatype trong mt namespace no . Phn trong {} c lp li nhiu ln v trong cc element c nhiu attribute.

<binding>
M t cc chi tit r rng ca web service. N ging nh l lp ci t mt interface trong Java.
<binding> <soap:binding ... /> {<operation> <soap:operation ... /> <input> <soap:input> </input> <output> <soap:output> </output> </operation> } </binding>

Attributes of <binding>
style: nhn gi tr rpc hoc document. rpc ngha l cc phn trong message ch s dng cc kiu d liu c bn c sn trong namespace http://www.w3.org/2001/XMLSchema . Gi tr document ngha l cc message c s dng cc element c nh ngha bi ngi s dng. use : nhn gi tr literal hoc encoded. Gi tr literal ngha l nh ngha kiu d liu ca service theo ng nguyn vn XML schema ca WSDL, cn gi tr encoded ngha l l nh ngha kiu d liu ca service theo cc lut m ha no , thng l cc lut m ha trong c t SOAP 1.1. Vic s dng encoded l khng tng thch chun WS-I nn t c s dng.

<service>
nh ngha mt hoc nhiu endpoint m service hot ng. Mt endpoint c m t l mt URL m cc message c th gi ti m s dng dch v. Service s lit k mt hoc nhiu port, mi port gm mt portType (interface) v mt binding(implementation). <service name=...> <port name=... binding=...> <soap:address location=... /> </port> </service> Thut ng port l ly t giao thc TCP, trong , mt kt ni c m t bi mt cp <IPAddress, PortNumber>, mi port ti mt IPAdress s phc v mt dch v nht nh.

SOAP
SOAP l giao thc c dng m cc web service lin lc c vi nhau. SOAP c 2 phin bn: SOAP 1.1(nm 2000, trong , SOAP l vit tt ca Simple Object Access Protocol), SOAP 1.2(nm 2003, trong , SOAP tr thnh danh t ring). a s cc web service m em gp (nh AmazonWebService) u c h tr cc giao thc SOAP 1.1 bn cnh SOAP1.2, HTTP GET, HTTP POST.

SOAP messages

SOAP request message


<?xml version="1.0" ?> <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Body> <GetDownloadURL xmlns="http://www.ecubicle.net/"> <fileURL>http://www.youtube.com/watch?v=Z4t8LrUSTMo</fileURL> </GetDownloadURL> </S:Body> </S:Envelope>

SOAP response message


<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <GetDownloadURLResponse xmlns="http://www.ecubicle.net/">

<GetDownloadURLResult>http://www.youtube.com/get_video?video_id=Z4t8LrU STMo&amp;l=255&amp;sk=HHKkhrTi_MBfwyOl9RjxYrKsN2Fgd4wC&amp;fm t_map=35%2F640000%2F9%2F0%2F115%2C34%2F0%2F9%2F0%2F115%2C5 %2F0%2F7%2F0%2F0&amp;t=vjVQa1PpcFNF57VeqNKmEadvgzruTu8xpwNR MkWPI%3D&amp;hl=en&amp;plid=AARsgq_hLYy9qaVM&amp;keywords=NA SA%252CShuttle%252CRSS%2520Retraction&amp;cr=US </GetDownloadURLResult> </GetDownloadURLResponse> </soap:Body> </soap:Envelope>

Kiu ca cc SOAP message c nh ngha trong vn bn WSDL.


<wsdl:types> <s:schema elementFormDefault="qualified" targetNamespace="http://www.ecubicle.net/"> <s:element name="GetDownloadURL"> <s:complexType> <s:sequence> <s:element minOccurs="0" maxOccurs="1" name="fileURL" type="s:string" /> </s:sequence> </s:complexType> </s:element> <s:element name="GetDownloadURLResponse"> <s:complexType> <s:sequence> <s:element minOccurs="0" maxOccurs="1" name="GetDownloadURLResult" type="s:string" /> </s:sequence> </s:complexType> </s:element> <s:element name="string" nillable="true" type="s:string" /> </s:schema> </wsdl:types> <wsdl:message name="GetDownloadURLSoapIn"> <wsdl:part name="parameters" element="tns:GetDownloadURL" /> </wsdl:message> <wsdl:message name="GetDownloadURLSoapOut"> <wsdl:part name="parameters" element="tns:GetDownloadURLResponse" /> </wsdl:message

V d minh ha
Pht trin 1 web service Encrypt
C 1 phng thc l int getEncryptionNumber(String str) Tr li 1 m ha tng ng ca 1 xu.

Ci t web service trn Tomcat 6.0


Ch : cc lib ca JAX-WS c ci t vo Tomcat 6.0

C ch hot ng
Mi ln web application c initialized, WSServletContextListener s c sun-jaxws.xml v to ra 1 java.util.List cc objects RuntimeEndpointInfo. Sau , n gi deploy() method ca tng object to ra 1 RuntimeModel s dng RuntimeModeler. Tc l: RuntimeModeler to ra 1 runtime model ca 1 SEI (portClassservice endpoint interface) lp ci t Web service endpoint. Mi RuntimeModel l mt model ca a web service v c th x l c cc request n

Pht trin s dng JAX-WS


Request SOAP message com.sun.xml.ws.tra nsport.http.servlet. WSServlet Response SOAP message Response SOAP message Request SOAP message

Web service

Pht trin t WSDL


wsdl SOSEServlet WSDL document

Request SOAP message SOSEServlet Response SOAP message

You might also like