You are on page 1of 11

WEB SERVICES LAB

M.TECH (Computer Science Engineering)


INDEX
S.N. CNTENTS !A"E N.
# Write $ progr$m to imp%ement WSDL Ser&ice (He%%o Ser&ice. WSDL
'i%e)
( Write $ progr$m t)e *er&ice pro&i+er c$n ,e imp%ement $ *ing%e
get!rice()- *t$tic ,in+() $n+ get!ro+uct oper$tion.
. 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.
(,) Re/ue*t 3 Re*pon*e
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%)
6 SA! en&e%ope 5or t)e regi*tr$tion
7 Write $ progr$m to imp%ement
$) We, ,$*e+ *er&ice con*umer
WEB SERVICES LAB
,8ecti&e*9
To implement the technologies like WSDL, UDDI.
To learn how to implement and deploy web service client and server
#) Write $ progr$m to imp%ement WSDL Ser&ice (He%%o Ser&ice.0*+% 'i%e)
<!ml version"#$.%# encoding"#UT&'(#)
<de*initions name"#+elloService#
target,amespace"#http-..www.ecerami.com.wsdl.+elloService.wsdl#
!mlns"#http-..schemas.!mlsoap.org.wsdl.#
!mlns-soap"#http-..schemas.!mlsoap.org.wsdl.soap.#
!mlns-tns"#http-..www.ecerami.com.wsdl.+elloService.wsdl#
!mlns-!sd"#http-..www.w/.org.0%%$.12LSchema#)

<message name"#Say+ello3e45est#)
<part name"#*irst,ame# type"#!sd-string#.)
<.message)
<message name"#Say+ello3esponse#)
<part name"#greeting# type"#!sd-string#.)
<.message)

<portType name"#+ello67ortType#)
<operation name"#say+ello#)
<inp5t message"#tns-Say+ello3e45est#.)
<o5tp5t message"#tns-Say+ello3esponse#.)
<.operation)
<.portType)

<binding name"#+ello68inding# type"#tns-+ello67ortType#)
<soap-binding style"#rpc#
transport"#http-..schemas.!mlsoap.org.soap.http#.)
<operation name"#say+ello#)
<soap-operation soap9ction"#say+ello#.)
<inp5t)
<soap-body
encodingStyle"#http-..schemas.!mlsoap.org.soap.encoding.#
namespace"#5rn-e!amples-helloservice#
5se"#encoded#.)
<.inp5t)
<o5tp5t)
<soap-body
encodingStyle"#http-..schemas.!mlsoap.org.soap.encoding.#
namespace"#5rn-e!amples-helloservice#
5se"#encoded#.)
<.o5tp5t)
<.operation)
<.binding)

<service name"#+ello6Service#)
<doc5mentation)WSDL &ile *or +elloService<.doc5mentation)
<port binding"#tns-+ello68inding# name"#+ello67ort#)
<soap-address
location"#http-..localhost-(%(%.soap.servlet.rpcro5ter#.)
<.port)
<.service)
<.de*initions)
() Write $ progr$m t)e *er&ice pro&i+er c$n ,e imp%ement $ *ing%e get!rice()- *t$tic ,in+() $n+
get!ro+uct oper$tion.
package com.ecerami.soap.e!amples:
import ;ava.5til.+ashtable:
.<<
< 9 Sample S=97 Service
< 7rovides >5rrent 7rice *or re45ested Stockkeeping Unit ?S@UA
<.
p5blic class 7riceService B
protected +ashtable prod5cts:

.<<
< 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

!mlns-tns"Mhttp-..www.themindelectric.com.wsdl.com.ecerami.soap.
e!amples.7riceService.M
!mlns-electric"Mhttp-..www.themindelectric.com.M
!mlns-soap"Mhttp-..schemas.!mlsoap.org.wsdl.soap.M
!mlns-http"Mhttp-..schemas.!mlsoap.org.wsdl.http.M
!mlns-mime"Mhttp-..schemas.!mlsoap.org.wsdl.mime.M
!mlns-!sd"Mhttp-..www.w/.org.0%%$.12LSchemaM
!mlns-soapenc"Mhttp-..schemas.!mlsoap.org.soap.encoding.M
!mlns-wsdl"Mhttp-..schemas.!mlsoap.org.wsdl.M
!mlns"Mhttp-..schemas.!mlsoap.org.wsdl.M)
<message name"Mget7rice%SoapInM)
<part name"Msk5M type"M!sd-stringM.)
<.message)
<message name"Mget7rice%Soap=5tM)
<part name"M3es5ltM type"M!sd-do5bleM.)
<.message)
<portType name"Mcom.ecerami.soap.e!amples.7riceServiceSoapM)
<operation name"Mget7riceM parameter=rder"Msk5M)
<inp5t name"Mget7rice%SoapInM message"Mtns-get7rice%SoapInM.)
<o5tp5t name"Mget7rice%Soap=5tM message"Mtns-get7rice%Soap=5tM.)
<.operation)
<.portType)
<binding name"Mcom.ecerami.soap.e!amples.7riceServiceSoapM
type"Mtns-com.ecerami.soap.e!amples.7riceServiceSoapM)
<soap-binding style"MrpcM
transport"Mhttp-..schemas.!mlsoap.org.soap.httpM.)
<operation name"Mget7riceM)
<soap-operation soap9ction"Mget7riceM style"MrpcM.)
<inp5t name"Mget7rice%SoapInM)
<soap-body 5se"MencodedM
namespace"M5rn-e!amples-priceserviceM
encodingStyle"Mhttp-..schemas.!mlsoap.org.soap.encoding.M.)
<.inp5t)
<o5tp5t name"Mget7rice%Soap=5tM)
<soap-body 5se"MencodedM
namespace"M5rn-e!amples-priceserviceM
encodingStyle"Mhttp-..schemas.!mlsoap.org.soap.encoding.M.)
<.o5tp5t)
<.operation)
<.binding)
<service name"Mcom.ecerami.soap.e!amples.7riceServiceM)
<port name"Mcom.ecerami.soap.e!amples.7riceServiceSoapM
binding"Mtns-com.ecerami.soap.e!amples.7riceServiceSoapM)
<soap-address location"Mhttp-..0%O.0/O.0%$.$(O-(%(%
.soap.servlet. rpcro5terM.)
<.port)
<.service)
<.de*initions)
,) get pro+uct oper$tion
<!ml version"#$.%#)
<de*initions name"#e8ayWatcherService#
target,amespace"
#http-..www.!methods.net.sd.e8ayWatcherService.wsdl#
!mlns-tns"#http-..www.!methods.net.sd.e8ayWatcherService.wsdl#
!mlns-!sd"#http-..www.w/.org.0%%$.12LSchema#
!mlns-soap"#http-..schemas.!mlsoap.org.wsdl.soap.#
!mlns"#http-..schemas.!mlsoap.org.wsdl.#)

<message name"#get>5rrent7rice3e45est#)
<part name"#a5ction6id# type " #!sd-string#.)
<.message)
<message name"#get>5rrent7rice3esponse#)
<part name"#ret5rn# type " #!sd-*loat#.)
<.message)

<portType name"#e8ayWatcher7ortType#)
<operation name"#get>5rrent7rice#)
<inp5t
message"#tns-get>5rrent7rice3e45est#
name"#get>5rrent7rice#.)
<o5tp5t
message"#tns-get>5rrent7rice3esponse#
name"#get>5rrent7rice3esponse#.)
<.operation)
<.portType)

<binding name"#e8ayWatcher8inding# type"#tns-e8ayWatcher7ortType#)
<soap-binding
style"#rpc#
transport"#http-..schemas.!mlsoap.org.soap.http#.)
<operation name"#get>5rrent7rice#)
<soap-operation soap9ction"##.)
<inp5t name"#get>5rrent7rice#)
<soap-body
5se"#encoded#
namespace"#5rn-!methods'JbayWatcher#
encodingStyle"#http-..schemas.!mlsoap.org.soap.encoding.#.)
<.inp5t)
<o5tp5t name"#get>5rrent7rice3esponse#)
<soap-body
5se"#encoded#
namespace"#5rn-!methods'JbayWatcher#
encodingStyle"#http-..schemas.!mlsoap.org.soap.encoding.#.)
<.o5tp5t)
<.operation)
<.binding)

<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

You might also like