Web Services - A Brief Introduction

  • Upload
    apextgi

  • View
    213

  • Download
    0

Embed Size (px)

Citation preview

  • 8/10/2019 Web Services - A Brief Introduction

    1/13

  • 8/10/2019 Web Services - A Brief Introduction

    2/13

    What is a Web Service ?What is a Web Service ?

    Web service is a means by which compters ta!" to each other over theWeb service is a means by which compters ta!" to each other over theweb 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 serverRns on a Web server* E+poses Web metho&s to intereste& ca!!ersE+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&smetho&s

    * E+ectes Web metho&s an& retrns the res!tsE+ectes Web metho&s an& retrns the res!ts

    http://www.apextgi.in/http://www.apextgi.in/
  • 8/10/2019 Web Services - A Brief Introduction

    3/13

    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!0SO(% /Simp!e Ob1ect (ccess %rotoco!0

    * UDDI /Universa! Description2 Discovery an& Inte#ration0UDDI /Universa! Description2 Discovery an& Inte#ration0

    * WS3%O,IC4 /Web Services %o!icy0WS3%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'

    http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/
  • 8/10/2019 Web Services - A Brief Introduction

    4/13

    Samp!e web serviceSamp!e web serviceCa!c'asm+Ca!c'asm+

    789 WebService ,an#a#e:;C(ppCo&e>WebService'cs; C!ass:;WebService;789 WebService ,an#a#e:;C(ppCo&e>WebService'cs; C!ass:;WebService;

    8@8@

    sin# SystemAsin# SystemA

    sin# System'Web'ServicesAsin# System'Web'ServicesA

    WebService /Name:;Ca!c!ator Web Service;2WebService /Name:;Ca!c!ator Web Service;2Description : ;%er-orm simp!e math over the Web;0Description : ;%er-orm simp!e math over the Web;0

    c!ass Ca!cServicec!ass Ca!cService

    Web5etho& /Description : ;Comptes the sm o- two inte#ers;0Web5etho& /Description : ;Comptes the sm o- two inte#ers;0

    pb!ic int (&& /int a2 int b0 retrn abAFpb!ic int (&& /int a2 int b0 retrn abAF

    Web5etho& /Description : ;Comptes the &i--erence between two inte#ers;0Web5etho& /Description : ;Comptes the &i--erence between two inte#ers;0pb!ic int Sbtract /int a2 int b0 retrn a3bAFpb!ic int Sbtract /int a2 int b0 retrn a3bAF

    FF

    http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/
  • 8/10/2019 Web Services - A Brief Introduction

    5/13

    The example demonstrates several important principlesof Web service programmingThe example demonstrates several important principlesof Web service programming

    using the .NET Framework:using the .NET Framework:

    Web services are implemented in !"# files. !"# is a special file name extensionWeb 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 mustcontain 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 inWeb service classes can be attributed with optional Web!ervice attributes. The one inthe previous example assigns the Web service a name and a description that show up inthe 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 withWeb methods are declared b& tagging public methods in the Web service class with

    Web"ethod attributes. -ou can build helper methods into a Web servicemethods thatWeb"ethod attributes. -ou can build helper methods into a Web servicemethods thatare used internall& b& Web methods but that are not exposed as Web methodsare used internall& b& Web methods but that are not exposed as Web methods

    themselvesb& omitting the Webmethod attribute.themselvesb& omitting the Webmethod attribute.

    http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/
  • 8/10/2019 Web Services - A Brief Introduction

    6/13

    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", pagethat describes the Web service.that describes the Web service.

    The name and description in the !"# file2s Web!ervice attribute appear at the top ofThe name and description in the !"# file2s Web!ervice attribute appear at the top ofthe page.the page.

    3nderneath is a list of Web methods that the service exposes' complete with the3nderneath is a list of Web methods that the service exposes' complete with thedescriptions 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 totest 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 themetadata in the 6,, it compiled from +alc.asmx. 7t even generates an (T", form thatmetadata 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 windowThe #", returned b& the Web method appears in a separate browser window

    The forms that !$.NET generates on the fl& from !"# files enable &ou toThe forms that !$.NET generates on the fl& from !"# files enable &ou totest the Web services that &ou write without writing special clients to test themtest the Web services that &ou write without writing special clients to test themwith.with.

    http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/
  • 8/10/2019 Web Services - A Brief Introduction

    7/13

    !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 !ubtractthat callers can use to add and subtract simple integers. 7f the service2s 38, isthat callers can use to add and subtract simple integers. 7f the service2s 38, iswww.wintellect.com9calc.asmxwww.wintellect.com9calc.asmx' here2s how a client would invoke the dd method b&' here2s how a client would invoke the dd method b&transmitting atransmitting a !$ envelope!$ envelopein 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: text9xmlxml? charset@utf>A? charset@utf>A

    +ontent>,ength: BBA+ontent>,ength: BBA

    !$ction!$ction:: http:99tempuri.org9ddhttp:99tempuri.org9dd

    C/xml version@D=.D encoding@Dutf>AD/C/xml version@D=.D encoding@Dutf>AD/CCsoap:Envelopesoap:Envelopexmlns:xsi@Dhttp:99www.wB.org9;=9#",!chema instanceDxmlns:xsi@Dhttp:99www.wB.org9;=9#",!chema instanceD

    xmlns: xsd@http:99www.wB.org9;=9#",!chemaxmlns: xsd@http:99www.wB.org9;=9#",!chema

    xmlns:soap@Dhttp:99schemas.xmlsoap.org9soap9envelope9Dxmlns:soap@Dhttp:99schemas.xmlsoap.org9soap9envelope9D

    CCsoap:God&soap:God&

    CCddddxmlns@Dhttp:99tempuri.org9Dxmlns@Dhttp:99tempuri.org9DCa;C9aCa;C9a

    Cb;C9bCb;C9b

    C9ddC9dd

    C9soap:God&C9soap:God&

    C9soap:EnvelopeC9soap:Envelope

    http://www.apextgi.in/http://www.apextgi.in/http://tempuri.org/Addhttp://tempuri.org/Addhttp://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://tempuri.org/Addhttp://www.apextgi.in/
  • 8/10/2019 Web Services - A Brief Introduction

    8/13

    nd here2s how the Web service would respond:nd here2s how the Web service would respond:

    (TT$9=.= ; H(TT$9=.= ; H

    +ontent>T&pe: text9+ontent>T&pe: text9xmlxml? charset@utf>A? charset@utf>A+ontent>,ength: BIB+ontent>,ength: BIB

    C/xml version@D=.D encoding@Dutf>AD/C/xml version@D=.D encoding@Dutf>AD/

    Csoap:Envelope xmlns:xsi@http:99www.wB.org9;=9#",!chema>instanceCsoap:Envelope xmlns:xsi@http:99www.wB.org9;=9#",!chema>instance

    xmlns:xsd@http:99www.wB.org9;=9#",!chemaxmlns:xsd@http:99www.wB.org9;=9#",!chema

    xmlns:soap@Dhttp:99schemas.xmlsoap.org9soap9envelope9Dxmlns:soap@Dhttp:99schemas.xmlsoap.org9soap9envelope9D

    Csoap:God&Csoap:God&

    CCdd8esponsedd8esponsexmlns@Dhttp:99tempuri.org9Dxmlns@Dhttp:99tempuri.org9D

    CCdd8esultdd8esultJC9dd8esultJC9dd8esult

    C9dd8esponseC9dd8esponse

    C9soap:God&C9soap:God&C9soap:EnvelopeC9soap:Envelope

    http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/
  • 8/10/2019 Web Services - A Brief Introduction

    9/13

    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 theand ;' formulate a !$ envelope containing the sum of ; and ;' and return it to theclient in the bod& of the (TT$ response. This' at the most elemental level' is what Webclient in the bod& of the (TT$ response. This' at the most elemental level' is what Webservices are all about.services are all about.

    Web services written with the .NET Framework also allow their Web methods toWeb services written with the .NET Framework also allow their Web methods tobe invoked using ordinar& (TT$ KET and $!T commands. The followingbe invoked using ordinar& (TT$ KET and $!T commands. The following KETKETcommand adds ; and ; b& invoking the Web service2s dd method:command adds ; and ; b& invoking the Web service2s dd method:

    KETKET9calc.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=.= ; H(TT$9=.= ; H

    +ontent>T&pe: text9xml? charset@utf>A+ontent>T&pe: text9xml? charset@utf>A

    +ontent>,ength: A+ontent>,ength: A

    C/xml version@D=.D encoding@Dutf>AD/C/xml version@D=.D encoding@Dutf>AD/

    CCintintxmlns@Dhttp:99tempuri.org9DJC9intxmlns@Dhttp:99tempuri.org9DJC9int

    http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/
  • 8/10/2019 Web Services - A Brief Introduction

    10/13

    (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=.= ; H(TT$9=.= ; H

    +ontent>T&pe: text9xml? charset@utf>A+ontent>T&pe: text9xml? charset@utf>A

    +ontent>,ength: A+ontent>,ength: A

    C/xml version@D=.D encoding@Dutf>AD/C/xml version@D=.D encoding@Dutf>AD/

    CCintintxmlns@Dhttp:99tempuri.org9DJC9intxmlns@Dhttp:99tempuri.org9DJC9int

    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 Webservice clients alike.service clients alike.

    http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/
  • 8/10/2019 Web Services - A Brief Introduction

    11/13

    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 &ou7f 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 publishesWhat Web methods &our service publishes What protocols it supportsWhat protocols it supports

    The signatures of its methodsThe 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 Webll 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.org9T89wsdlhttp:99www.wB.org9T89wsdl..

    http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.w3.org/TR/wsdlhttp://www.apextgi.in/
  • 8/10/2019 Web Services - A Brief Introduction

    12/13

    Web !ervice 6iscover&67!+ and 3667Web !ervice 6iscover&67!+ and 3667

    nce a client has a W!6, contract describing a Web service' it has all thence 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 dohow 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' for67!+ is a file>based mechanism for local Web service discover&that is' forgetting 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.

    http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/http://www.apextgi.in/
  • 8/10/2019 Web Services - A Brief Introduction

    13/13