You are on page 1of 13

INTRODUCTION TO WEB

INTRODUCTION TO WEB
SERVICES
SERVICES
What is a Web Service ?
What is a Web Service ?
Web service is a means by which compters ta!" to each other over the Web service is a means by which compters ta!" to each other over the
web sin# $TT% an& other niversa!!y spporte& protoco!s' web sin# $TT% an& other niversa!!y spporte& protoco!s'
( Web service is an app!ication that) ( Web service is an app!ication that)
* Rns on a Web server Rns on a Web server
* E+poses Web metho&s to intereste& ca!!ers E+poses Web metho&s to intereste& ca!!ers
* ,istens -or $TT% re.ests representin# comman&s to invo"e Web ,istens -or $TT% re.ests representin# comman&s to invo"e Web
metho&s metho&s
* E+ectes Web metho&s an& retrns the res!ts E+ectes Web metho&s an& retrns the res!ts
Web Services is base& on)
Web Services is base& on)
* $TT% /$yperte+t Transport %rotoco!0 $TT% /$yperte+t Transport %rotoco!0
* SO(% /Simp!e Ob1ect (ccess %rotoco!0 SO(% /Simp!e Ob1ect (ccess %rotoco!0
* UDDI /Universa! Description2 Discovery an& Inte#ration0 UDDI /Universa! Description2 Discovery an& Inte#ration0
* WS3%O,IC4 /Web Services %o!icy0 WS3%O,IC4 /Web Services %o!icy0
5ost Web services e+pect their Web metho&s to be invo"e& sin# 5ost Web services e+pect their Web metho&s to be invo"e& sin#
$TT% re.ests containin# SO(% messa#es' SO(% is an 65,3base& $TT% re.ests containin# SO(% messa#es' SO(% is an 65,3base&
vocab!ary -or per-ormin# remote proce&re ca!!s sin# $TT% an& vocab!ary -or per-ormin# remote proce&re ca!!s sin# $TT% an&
other protoco!s' other protoco!s'
Samp!e web service
Samp!e web service
Ca!c'asm+ Ca!c'asm+
789 WebService ,an#a#e:;C<; Co&eBehin&:;=>(pp?Co&e>WebService'cs; C!ass:;WebService; 789 WebService ,an#a#e:;C<; Co&eBehin&:;=>(pp?Co&e>WebService'cs; C!ass:;WebService;
8@ 8@
sin# SystemA sin# SystemA
sin# System'Web'ServicesA sin# System'Web'ServicesA
BWebService /Name:;Ca!c!ator Web Service;2 BWebService /Name:;Ca!c!ator Web Service;2
Description : ;%er-orm simp!e math over the Web;0C Description : ;%er-orm simp!e math over the Web;0C
c!ass Ca!cService c!ass Ca!cService
D D
BWeb5etho& /Description : ;Comptes the sm o- two inte#ers;0C BWeb5etho& /Description : ;Comptes the sm o- two inte#ers;0C
pb!ic int (&& /int a2 int b0 D retrn aEbAF pb!ic int (&& /int a2 int b0 D retrn aEbAF
BWeb5etho& /Description : ;Comptes the &i--erence between two inte#ers;0C BWeb5etho& /Description : ;Comptes the &i--erence between two inte#ers;0C
pb!ic int Sbtract /int a2 int b0 D retrn a3bAF pb!ic int Sbtract /int a2 int b0 D retrn a3bAF
F F
The example demonstrates several important principles of Web service programming The example demonstrates several important principles of Web service programming
using the .NET Framework: using the .NET Framework:
Web services are implemented in !"# files. !"# is a special file name extension Web services are implemented in !"# files. !"# is a special file name extension
registered to !$.NET %specificall&' to an !$.NET (TT$ handler) in "achine.config. registered to !$.NET %specificall&' to an !$.NET (TT$ handler) in "achine.config.
!"# files begin with * Web!ervice directives. t a minimum' the directive must !"# files begin with * Web!ervice directives. t a minimum' the directive must
contain a +lass attribute identif&ing the class that makes up the Web service. contain a +lass attribute identif&ing the class that makes up the Web service.
Web service classes can be attributed with optional Web!ervice attributes. The one in Web service classes can be attributed with optional Web!ervice attributes. The one in
the previous example assigns the Web service a name and a description that show up in the previous example assigns the Web service a name and a description that show up in
the (T", page generated when a user calls up +alc.asmx in his or her browser. the (T", page generated when a user calls up +alc.asmx in his or her browser.
Web methods are declared b& tagging public methods in the Web service class with Web methods are declared b& tagging public methods in the Web service class with
Web"ethod attributes. -ou can build helper methods into a Web service.methods that Web"ethod attributes. -ou can build helper methods into a Web service.methods that
are used internall& b& Web methods but that are not exposed as Web methods are used internall& b& Web methods but that are not exposed as Web methods
themselves.b& omitting the Webmethod attribute. themselves.b& omitting the Webmethod attribute.
Testing a Web !ervice : Testing a Web !ervice :
(ow do &ou test an !"# Web service/ !imple: 0ust call it up in &our browser. (ow do &ou test an !"# Web service/ !imple: 0ust call it up in &our browser.

!$.NET responds to the (TT$ re1uest for +alc.asmx b& generating an (T", page !$.NET responds to the (TT$ re1uest for +alc.asmx b& generating an (T", page
that describes the Web service. that describes the Web service.
The name and description in the !"# file2s Web!ervice attribute appear at the top of The name and description in the !"# file2s Web!ervice attribute appear at the top of
the page. the page.
3nderneath is a list of Web methods that the service exposes' complete with the 3nderneath is a list of Web methods that the service exposes' complete with the
descriptions spelled out in the Web"ethod attributes. descriptions spelled out in the Web"ethod attributes.
+lick 4dd5 near the top of the page' and !$.NET displa&s a page that &ou can use to +lick 4dd5 near the top of the page' and !$.NET displa&s a page that &ou can use to
test the dd method . test the dd method .
!$.NET knows the method name and signature because it reads them from the !$.NET knows the method name and signature because it reads them from the
metadata in the 6,, it compiled from +alc.asmx. 7t even generates an (T", form that metadata in the 6,, it compiled from +alc.asmx. 7t even generates an (T", form that
&ou can use to call the dd method with &our choice of inputs. &ou can use to call the dd method with &our choice of inputs.
The #", returned b& the Web method appears in a separate browser window The #", returned b& the Web method appears in a separate browser window

The forms that !$.NET generates on the fl& from !"# files enable &ou to The forms that !$.NET generates on the fl& from !"# files enable &ou to
test the Web services that &ou write without writing special clients to test them test the Web services that &ou write without writing special clients to test them
with. with.
!uppose &ou write a Web service that publishes Web methods named dd and !ubtract !uppose &ou write a Web service that publishes Web methods named dd and !ubtract
that callers can use to add and subtract simple integers. 7f the service2s 38, is that callers can use to add and subtract simple integers. 7f the service2s 38, is
www.wintellect.com9calc.asmx www.wintellect.com9calc.asmx' here2s how a client would invoke the dd method b& ' here2s how a client would invoke the dd method b&
transmitting a transmitting a !:$ envelope !:$ envelope in an (TT$ re1uest. This example adds ; and ;: in an (TT$ re1uest. This example adds ; and ;:
$:!T $:!T9calc.asmx(TT$9=.= 9calc.asmx(TT$9=.=
(ost:www.wintellect.com (ost:www.wintellect.com
+ontent>T&pe:text9 +ontent>T&pe:text9xml xml?charset@utf>A ?charset@utf>A
+ontent>,ength:BBA +ontent>,ength:BBA
!:$ction !:$ction: : http:99tempuri.org9dd http:99tempuri.org9dd
C/xmlversion@D=.ED encoding@Dutf>AD/F C/xmlversion@D=.ED encoding@Dutf>AD/F
C Csoap:Envelope soap:Envelopexmlns:xsi@Dhttp:99www.wB.org9;EE=9#",!chema instanceD xmlns:xsi@Dhttp:99www.wB.org9;EE=9#",!chema instanceD
xmlns: xsd@http:99www.wB.org9;EE=9#",!chema xmlns: xsd@http:99www.wB.org9;EE=9#",!chema
xmlns:soap@Dhttp:99schemas.xmlsoap.org9soap9envelope9DF xmlns:soap@Dhttp:99schemas.xmlsoap.org9soap9envelope9DF
C Csoap:God& soap:God&F F
C Cdd ddxmlns@Dhttp:99tempuri.org9DF xmlns@Dhttp:99tempuri.org9DF
CaF;C9aF CaF;C9aF
CbF;C9bF CbF;C9bF
C9ddF C9ddF
C9soap:God&F C9soap:God&F
C9soap:EnvelopeF C9soap:EnvelopeF
nd here2s how the Web service would respond: nd here2s how the Web service would respond:
(TT$9=.=;EE:H (TT$9=.=;EE:H
+ontent>T&pe:text9 +ontent>T&pe:text9xml xml?charset@utf>A ?charset@utf>A
+ontent>,ength:BIB +ontent>,ength:BIB
C/xmlversion@D=.ED encoding@Dutf>AD/F C/xmlversion@D=.ED encoding@Dutf>AD/F
Csoap:Envelopexmlns:xsi@http:99www.wB.org9;EE=9#",!chema>instance Csoap:Envelopexmlns:xsi@http:99www.wB.org9;EE=9#",!chema>instance
xmlns:xsd@http:99www.wB.org9;EE=9#",!chema xmlns:xsd@http:99www.wB.org9;EE=9#",!chema
xmlns:soap@Dhttp:99schemas.xmlsoap.org9soap9envelope9DF xmlns:soap@Dhttp:99schemas.xmlsoap.org9soap9envelope9DF
Csoap:God&F Csoap:God&F
C Cdd8esponse dd8esponsexmlns@Dhttp:99tempuri.org9DF xmlns@Dhttp:99tempuri.org9DF
C Cdd8esult dd8esultFJC9dd8esultF FJC9dd8esultF
C9dd8esponseF C9dd8esponseF
C9soap:God&F C9soap:God&F
C9soap:EnvelopeF C9soap:EnvelopeF
The Web service2s 0ob is to parse the !:$ envelope containing the inputs' add ; The Web service2s 0ob is to parse the !:$ envelope containing the inputs' add ;
and ;' formulate a !:$ envelope containing the sum of ; and ;' and return it to the and ;' formulate a !:$ envelope containing the sum of ; and ;' and return it to the
client in the bod& of the (TT$ response. This' at the most elemental level' is what Web client in the bod& of the (TT$ response. This' at the most elemental level' is what Web
services are all about. services are all about.
Web services written with the .NET Framework also allow their Web methods to Web services written with the .NET Framework also allow their Web methods to
be invoked using ordinar& (TT$ KET and $:!T commands. The following be invoked using ordinar& (TT$ KET and $:!T commands. The following KET KET
command adds ; and ; b& invoking the Web service2s dd method: command adds ; and ; b& invoking the Web service2s dd method:
KET KET9calc.asmx9dd/a@;Lb@;(TT$9=.= 9calc.asmx9dd/a@;Lb@;(TT$9=.=
(ost:www.wintellect.com (ost:www.wintellect.com
The Web service responds as follows: The Web service responds as follows:
(TT$9=.=;EE:H (TT$9=.=;EE:H
+ontent>T&pe:text9xml?charset@utf>A +ontent>T&pe:text9xml?charset@utf>A
+ontent>,ength:AE +ontent>,ength:AE
C/xmlversion@D=.ED encoding@Dutf>AD/F C/xmlversion@D=.ED encoding@Dutf>AD/F
C Cint intxmlns@Dhttp:99tempuri.org9DFJC9intF xmlns@Dhttp:99tempuri.org9DFJC9intF
(ere2s a $:!T command that adds ; and ;: (ere2s a $:!T command that adds ; and ;:
$:!T $:!T9calc.asmx9dd(TT$9=.= 9calc.asmx9dd(TT$9=.=
(ost:www.wintellect.com (ost:www.wintellect.com
+ontent>T&pe:application9x>www>form>urlencoded +ontent>T&pe:application9x>www>form>urlencoded
+ontent>,ength:M +ontent>,ength:M
a@;Lb@; a@;Lb@;
nd here2s the Web service2s response: nd here2s the Web service2s response:
(TT$9=.=;EE:H (TT$9=.=;EE:H
+ontent>T&pe:text9xml?charset@utf>A +ontent>T&pe:text9xml?charset@utf>A
+ontent>,ength:AE +ontent>,ength:AE
C/xmlversion@D=.ED encoding@Dutf>AD/F C/xmlversion@D=.ED encoding@Dutf>AD/F
C Cint intxmlns@Dhttp:99tempuri.org9DFJC9intF xmlns@Dhttp:99tempuri.org9DFJC9intF
The hard part of writing a Web service is parsing (TT$ re1uests and generating (TT$ The hard part of writing a Web service is parsing (TT$ re1uests and generating (TT$
responses. The .NET Framework insulates developers from the low>level details of (TT$' responses. The .NET Framework insulates developers from the low>level details of (TT$'
!:$' and #", and provides a high>level framework for writing Web services and Web !:$' and #", and provides a high>level framework for writing Web services and Web
service clients alike. service clients alike.
Web !ervices 6escription ,anguage > W!6,
Web !ervices 6escription ,anguage > W!6,


7f other developers are to consume %that is' write clients for) a Web service that &ou 7f other developers are to consume %that is' write clients for) a Web service that &ou
author' the& need to know : author' the& need to know :
What Web methods &our service publishes What Web methods &our service publishes
What protocols it supports What protocols it supports
The signatures of its methods The signatures of its methods
The Web service2s location %38,) The Web service2s location %38,)
ll this information and more can be expressed in a language called the Web ll this information and more can be expressed in a language called the Web
!ervices 6escription ,anguage' or W!6, for short. !ervices 6escription ,anguage' or W!6, for short.
W!6, is an #", vocabular& W!6, is an #", vocabular& http:99www.wB.org9T89wsdl http:99www.wB.org9T89wsdl. .
Web !ervice 6iscover&.67!+: and 3667
Web !ervice 6iscover&.67!+: and 3667
:nce a client has a W!6, contract describing a Web service' it has all the :nce a client has a W!6, contract describing a Web service' it has all the
information it needs to make calls to that Web service. information it needs to make calls to that Web service.
Gut when &ou publish a Web service b& making it available on a Web server' Gut when &ou publish a Web service b& making it available on a Web server'
how do clients find out where to get a W!6, contract/ For that matter' how do how do clients find out where to get a W!6, contract/ For that matter' how do
clients know that &our Web service exists in the first place/ clients know that &our Web service exists in the first place/
The answer comes in two parts: The answer comes in two parts:
67!+: and 3niversal 6escription' 6iscover&' and 7ntegration %3667) 67!+: and 3niversal 6escription' 6iscover&' and 7ntegration %3667)
67!+: is a file>based mechanism for local Web service discover&.that is' for 67!+: is a file>based mechanism for local Web service discover&.that is' for
getting a list of available Web services from 67!+: files deplo&ed on Web servers. getting a list of available Web services from 67!+: files deplo&ed on Web servers.
3667 is a global Web service director& that is itself implemented as a Web service. 3667 is a global Web service director& that is itself implemented as a Web service.

You might also like