This document outlines a lab assignment for implementing web services. It includes:
1. Writing a program to implement a WSDL service file for a "Hello Service".
2. Writing a program for a service provider to implement single getPrice()-static binding and getProduct operation.
3. Writing a program to implement an operation that can receive a request and return a response in a new format.
Download as DOC, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
93 views
Web Services LAB Manual
This document outlines a lab assignment for implementing web services. It includes:
1. Writing a program to implement a WSDL service file for a "Hello Service".
2. Writing a program for a service provider to implement single getPrice()-static binding and getProduct operation.
3. Writing a program to implement an operation that can receive a request and return a response in a new format.
.<< < Cero 9rg5ment >onstr5ctor < Load prod5ct database with two sample prod5cts <. p5blic 7riceService ? A B prod5cts " new +ashtable? A: .. 3ed +at Lin5! prod5cts.p5t?#9/D($(D#, new Do5ble ?DE.FFAA: .. 2c9*ee 7G7 7ersonal 7rivacy prod5cts.p5t?#9/D(DHD#, new Do5ble ?$F.FFAA: I
.<< < 7rovides >5rrent 7rice *or re45ested S@U < In a real'set5p, this method wo5ld connect to < a price database. I* S@U is not *o5nd, method < will throw a 7riceJ!ception. <. p5blic do5ble get7rice ?String sk5A throws 7rod5ct,ot&o5ndJ!ception B Do5ble price " ?Do5bleA prod5cts.get?sk5A: i* ?price "" n5llA B throw new 7rod5ct,ot&o5ndJ!ception ?#S@U- #Ksk5K# not *o5nd#A: I ret5rn price.do5bleLal5e? A: I I <!ml version"M$.%M encoding"MUT&'(M) <N''generated by GLUJ'') <de*initions name"Mcom.ecerami.soap.e!amples.7riceServiceM target,amespace"Mhttp-..www.themindelectric.com.wsdl.com.ecerami.soap. e!amples.7riceService.M
<service name"#e8ayWatcherService#) <doc5mentation) >hecks c5rrent high bid *or an e8ay a5ction <.doc5mentation) <port name"#e8ayWatcher7ort# binding"#tns-e8ayWatcher8inding#) <soap-address location"#http-..services.!methods.net-(%.soap.servlet.rpcro5ter#.) <.port) <.service) <.de*initions) ..$) Write $ progr$m to imp%ement t)e oper$tion c$n recei&e re/ue*t $n+ 0i%% return re*pon*e in ne1W$2 oper$tion. import ;ava!.!ml.soap.<: import ;ava!.!ml.namespace.P,ame: import ;ava.5til.Iterator: import ;ava.net.U3L: p5blic class 3e45est B p5blic static void main?StringQR argsA B try B S=97>onnection&actory soap>onnection&actory " S=97>onnection&actory.newInstance?A: S=97>onnection connection " soap>onnection&actory.create>onnection?A: 2essage&actory *actory " 2essage&actory.newInstance?A: S=972essage message " *actory.create2essage?A: S=97+eader header " message.getS=97+eader?A: S=978ody body " message.getS=978ody?A: header.detach,ode?A: P,ame body,ame " new P,ame?#http-..wombat.Strade.com#, #GetLastTrade7rice#, #m#A: S=978odyJlement bodyJlement " body.add8odyJlement?body,ameA: P,ame name " new P,ame?#symbol#A: S=97Jlement symbol " bodyJlement.add>hildJlement?nameA: symbol.addTe!t,ode?#SU,W#A: U3L endpoint " new U3L?#http-..wombat.Strade.com.45otes#A: S=972essage response " connection.call?message, endpointA: connection.close?A: S=978ody soap8ody " response.getS=978ody?A: Iterator iterator " soap8ody.get>hildJlements?body,ameA: bodyJlement " ?S=978odyJlementAiterator.ne!t?A: String last7rice " bodyJlement.getLal5e?A: System.o5t.print?#The last price *or SU,W is #A: System.o5t.println?last7riceA: I catch ?J!ception e!A B e!.printStackTrace?A: I I I 4.Write $ progr$m to imp%ement to cre$te $ *imp%e 0e, *er&ice t)$t con&ert* t)e temper$ture 5rom'$)ren)eit to Ce%*iu* (u*ing HTT! !o*t !rotoco%) The *ollowing is a sample S=97 $.$ re45est and response. The placeholders shown need to be replaced with act5al val5es. 7=ST .webservices.tempconvert.asm! +TT7.$.$ +ost- www.w/schools.com >ontent'Type- te!t.!ml: charset"5t*'( >ontent'Length- length S=979ction- #http-..www.w/schools.com.webservices.>elsi5sTo&ahrenheit# <!ml version"#$.%# encoding"#5t*'(#) <soap-Jnvelope !mlns-!si"#http-..www.w/.org.0%%$.12LSchema'instance# !mlns-!sd"#http-..www.w/.org.0%%$.12LSchema# !mlns-soap"#http-..schemas.!mlsoap.org.soap.envelope.#) <soap-8ody) <>elsi5sTo&ahrenheit !mlns"#http-..www.w/schools.com.webservices.#) <>elsi5s)string<.>elsi5s) <.>elsi5sTo&ahrenheit) <.soap-8ody) <.soap-Jnvelope) +TT7.$.$ 0%% =@ >ontent'Type- te!t.!ml: charset"5t*'( >ontent'Length- length <!ml version"#$.%# encoding"#5t*'(#) <soap-Jnvelope !mlns-!si"#http-..www.w/.org.0%%$.12LSchema'instance# !mlns-!sd"#http-..www.w/.org.0%%$.12LSchema# !mlns-soap"#http-..schemas.!mlsoap.org.soap.envelope.#) <soap-8ody) <>elsi5sTo&ahrenheit3esponse !mlns"#http-..www.w/schools.com.webservices.#) <>elsi5sTo&ahrenheit3es5lt)string<.>elsi5sTo&ahrenheit3es5lt) <.>elsi5sTo&ahrenheit3esponse) <.soap-8ody) <.soap-Jnvelope) D. SA! en&e%ope 5or t)e regi*tr$tion <S=97'J,L- Jnvelope !mlns-S=97'J,L"#http-..schemas.!mlsoap.org.soap.envelope.# !mlns-!si"#http-..www.w/.org.$FFF.12LSchema'instance# !mlns-!sd"#http-..www.w/.org.$FFF.12LSchema#) <S=97'J,L-8ody) <save6b5siness generic"#$.%# !mlns"#5rn-5ddi'org-api#) <a5thln*o)test<.a5thln*o) <b5sinessJntity) <name)3ichard +5angMs<.name) <b5sinessServices) <b5sinessService) <name)+ello World Service<.name) <bindingTemplates) <bindingTemplate) <access7oint H$ 5rlType"#+TT7#)http-..localhost-(%(%<.access7oint) <.bindingTemplate) <.bindingTemplates) <.b5sinessService) <.b5sinessServices) <identi*ier8ag) <keyed3e*erence key,ame"#D'U','S# keyLalLie"#l0/EDHO(F%# T2odel@ey"#UUID-(H%F>(lJ'JJl&'EDD9'80%0'/J8l/9D=l(0/#.) <.identi*ier8ag) <category8ag) <keyed3e'*erence key,ame"#,9I>S# keyLal5e"T$$$FE# T+odel@ey"#UUID->=8F&J$/'$OF&'E$/D'(9D8'D%%ED8(JD880#.) <.category8ag) <.b5sinessJntity) <.save6b5siness) <.S=97'J,L-8ody) <.S=97'J,L- Jnvelope H.Write $ progr$m to imp%ement c) We, ,$*e+ *er&ice con*umer +) 'ir*tSer&ice.$*m: eA <UV WebService lang5age"#># class"#&irstService# U) *A gA 5sing System: hA 5sing System.Web.Services: iA 5sing System.1ml.SerialiSation: ;A kA QWebService?,amespace"#http-..localhost.2yWebServices.#AR lA p5blic class &irstService - WebService mA B nA QWeb2ethodR oA p5blic int 9dd?int a, int bA pA B 4A ret5rn a K b: rA I sA tA QWeb2ethodR 5A p5blic String Say+ello?A vA B wA ret5rn #+ello World#: !A I yA I
,) Win+o0* App%ic$tion1B$*e+ We, Ser&ice Con*umer WEB 0inApp.c* 5sing System: 5sing System.I=: namespace Svc>ons5merB class SvcJater B p5blic static void 2ain?StringQR argsA B &irstService mySvc " new &irstService?A: >onsole.WriteLine?#>alling +ello World Service- # K mySvc.Say+ello?AA: >onsole.WriteLine?#>alling 9dd?0, /A Service- # K mySvc.9dd?0, /A.ToString?AA: I I I