Вы находитесь на странице: 1из 41

VIVEKANANDA GROUP OF INSTITUTIONS

Batasingaram(V), Hayathanagar (!"), R#R#Dist$%&'%''#


DEPARTENT OF
COMPUTER SCIENCE AND ENGINEERING
#T()h I *(ar II S(m ( R'+ )
A,ADEI, *EAR -&'+ .-&'/
VIVEKANANDA GROUP OF INSTITUTIONS
Batasingaram(V), Hayathanagar (!"), R#R#Dist$%&'%''#
(Afliated to J.N.T.University, Hyderabad)
0EB SERVI,ES 1AB ANUA1
VIVEKANANDA GROUP OF INSTITUTIONS
DEPARTENT OF
COMPUTER SCIENCE AND ENGINEERING
,ERTIFI,ATE
This is to certify that Mr/Ms/_________________________bearing H.T.No. _________________
has satisfactorily completed the course of experiments in the practical _______________________
prescribed by the university for M.Tech __________ Year / Semester of ________ course/branch in the
laboratory of this college in the academic year !"# to !"$.
Signature of the %ab &aculty Head of the 'epartment
0EB SERVI,ES 1AB
TABLE OF CONTENTS
S.N
o
Title of the Program Pg#N2# Conduc
ted
Date
Sumitt
ed Date
Remar!"#
Signature
'
(rite a program to implement (S'% Service
)Hello Service . (S'% &ile*
'$3
-
(rite a program the service provider can be
implement a single get price)*+ static bind)* and
get
product operation.
'&$'/
+
(rite a program to implement the operation
can receive re,uest and -ill return a response
in
t-o -ays.
a* .ne/(ay operation
b* 0e,uest / 0esponse
'%$'3
$
(rite a program to implement to create a
simple -eb service that converts the
temperature from
&ahrenheit to 1elsius )using HTT2 2ost
2rotocol*
-&$--
%
(rite a program to implement business 3''4
0egistry entry
-+$-%
4
(rite a program to implement
a* (eb based service consumer
b* (indo-s application based -eb service
consumer
-4$+4
INTRODU,TION TO 0EB SERVI,ES
0HAT IS A 0EB SERVI,E 5
5 very simple definition is 6a service made available over the -eb6.
The difference bet-een a standard -ebsite and a -eb service is this7 a -ebsite is meant for human
consumption+ -hile a -eb service is meant for machine (or code) consumption. 4t allo-s t-o different
pieces of code running on t-o different servers to be able to tal8 to each other and call each other9s methods.
5 0(6 s(r7i)( is a method of communications bet-een t-o electronic devices over the (orld (ide (eb. 4t
is a soft-are function provided at a net-or8 address over the -eb -ith the service always on as in the
concept of utility computing.
5 complete -eb service is+ therefore+ any service that 7
4s available over the 4nternet or private )intranet* net-or8s
3ses a standardi:ed ;M% messaging system
4s not tied to any one operating system or programming language
4s self/describing via a common ;M% grammar
4s discoverable via a simple find mechanism
Figure - A basic web service
IP1EENTATION APPROA,HES
There are t-o basic approaches that are used to create -eb services from scratch.
The first approach is termed 9bottom/up9. This is -here the code that implements the operations performed by
the service is -ritten first. Then the ;M% description )(S'%* of the service is produced and published in
3''4. The service code is placed inside a 9container9 that provides the re,uired interface for messaging
)S.52 or something similar*.
The second approach is to produce the ;M% description of the service before it is implemented. So the
service is fully described in terms of -hat it does+ ho- it can be called and -hat result)s* it returns+ but is not
actually implemented. This )(S'%* specification is then used as a guide to -riting the code that implements
the service.
This approach is termed 9top/do-n9.
These t-o approaches are illustrated in &igure ".
'# 0rit( a 8r2gram t2 im8"(m(nt 0SD1 S(r7i)( (H(""2 S(r7i)( # 0SD1 Fi"()
0SD1
(S'% stands for (eb Services 'escription %anguage
(S'% is an ;M% based protocol for information exchange in decentrali:ed and distributed
environments.
(S'% is the standard format for describing a -eb service.
(S'% definition describes ho- to access a -eb service and -hat operations it -ill perform.
(S'% is a language for describing ho- to interface -ith ;M%/based services.
(S'% is an integral part of 3''4+ an ;M%/based -orld-ide business registry.
(S'% is the language that 3''4 uses.
(S'% -as developed <ointly by Microsoft and 4=M.
(S'% is pronounced as 9-i:/dull9 and spelled out as 9(/S/'/%9
(S'% describes four critical pieces of data7
4nterface information describing all publicly available functions
'ata type information for all message re,uests and message responses
=inding information about the transport protocol to be used
5ddress information for locating the specified service
Three ma<or elements of (S'% that can be defined separately and they are7
Types
.perations
=inding
5 (S'% document has various elements+ but they are contained -ithin these three main elements+ -hich can
be developed as separate documents and then they can be combined or reused to form complete (S'% files.
&ollo-ing are the elements of (S'% document. (ithin these elements are further sub elements+ or parts7
D(9initi2n : element must be the root element of all (S'% documents. 4t defines the name of the -eb
service+ declares multiple namespaces used throughout the remainder of the document+ and contains all the
service elements described here.
Data ty8(s : the data types / in the form of ;M% schemas or possibly some other mechanism / to be used in
the messages
(ssag( : an abstract definition of the data+ in the form of a message presented either as an entire document
or as arguments to be mapped to a method invocation.
O8(rati2n : the abstract definition of the operation for a message+ such as naming a method+ message ,ueue+
or business process+ that -ill accept and process the message
P2rt ty8( : an abstract set of operations mapped to one or more end points+ defining the collection of
operations for a binding> the collection of operations+ because it is abstract+ can be mapped to multiple
transports through various bindings.
Bin!ing : the concrete protocol and data formats for the operations and messages defined for a particular
port type.
P2rt : a combination of a binding and a net-or8 address+ providing the target address of the service
communication.
S(r7i)(: a collection of related end points encompassing the service definitions in the file> the services map
the binding to the port and include any extensibility definitions.
4n addition to these ma<or elements+ the (S'% specification also defines the follo-ing utility elements7
D2);m(ntati2n: element is used to provide human/readable documentation and can be included inside any
other (S'% element.
Im82rt: element is used to import other (S'% documents or ;M% Schemas.
N.T?7 (S'% parts usually are generated automatically using (eb services/a-are tools.
Th( 0SD1 D2);m(nt Str;)t;r(
The main structure of a (S'% document loo8s li8e this7
<defnitions>
<types>
defnition of types........
</types>
<message>
defnition of a message....
</message>
<portType>
<operation>
defnition of a operation.......
</operation>
</portType>
<binding>
defnition of a binding....
</binding>
<service>
defnition of a service....
</service>
</defnitions>
5 (S'% document can also contain other elements+ li8e extension elements and a service element that
ma8es it possible to group together the definitions of several -eb services in one single (S'% document.
5ssuming the service provides a single publicly available function+ called sayHello. This function expects a
single string parameter and returns a single string greeting. &or example if you pass the parameter world then
service function sayHello returns the greeting+ 6Hello+ -orld @.
,ODE :
,r(ating a Sim8"( 0(6 S(r7i)(
Tas< ' = ,r(ating a 0(6 S(r7i)(
Navigate to Start > Pr2grams > i)r2s29t Vis;a" St;!i2# NET -&'& > i)r2s29t Vis;a" St;!i2
#NET -&'&
Select Fi"(> N(? > Pr2@()t menu command
4n the 2ro<ect Types pane select Vis;a" ,A Pr2@()ts
4n the Templates pane+ clic8 ASP#NET 0(6 S(r7i)(
1lic8 OK
Tas< - = EB82sing a (th2! as a 0(6 S(r7i)(
Navigate to the Service".asmx file in S2";ti2n EB8"2r(r+ right/clic8 the file and select Vi(? ,2!(
1reate a ne- function called sayH(""2+ -hich ta8es a string parameter and returns a string
4mplement the method to return the result
5dd the C0(6(th2!()D attribute to the function. This attribute tells .N?T to expose the function as a
(eb Service.
[WebMethod]
public string sayHello(string name)
{
return ("Hello " + name + "!");

Tas< + = P(r92rm Initia" T(sting


0ight/clic8 Service".asmx in the S2";ti2n EB8"2r(r and clic8 S(t as Start Pag(
To compile your application press ,TR1EF%
Aisual Studio .N?T opens a (eb page+ to test the (eb Service -ithout implementing a specific client.
To vie- the test page+ clic8 the sayH(""2 lin8.
To invo8e the (eb Service from the test page+ enter a value in the Param(t(r and clic8 In72<(.
Below is a sample result when the input parameter is World.
<?xml version="1.0" encoding="utf-8" ?>
<string xmlns="http://tempuri.org/">ello !orld"</string>
?xamine the 0(6 S(r7i)( D(s)ri8ti2n 1ang;ag((0SD1) file that .N?T provides for users of your
service. To vie- the file clic8 the S(r7i)( D(s)ri8ti2n lin8 on the test page
?xamine the (S'% file. 'efinitions are provided for SOAP+ HTTP GET and HTTP POST
protocols to describe ho- the (eb Service can be accessed using different protocols. SOAP is used
by client applications to access a (eb Service+ -hile the (eb bro-ser uses the HTTP GET method
-hen calling the (eb Service )as -as done in this exercise*.
(ebService".asmx.cs
using !ystem;
using !ystem"#ollections"$eneric;
using !ystem"Web;
using !ystem"Web"!er%ices;
namespace Web!er%ice&
{
''' (summary)
''' !ummary description *or !er%ice&
''' ('summary)
[Web!er%ice(+amespace , "http-''tempuri"org'")]
[Web!er%ice.inding(#on*orms/o , Wsi0ro*iles".asic0ro*ile&1&)]
[!ystem"#omponentModel"/oolbo23tem(*alse)]
public class !er%ice& - !ystem"Web"!er%ices"Web!er%ice
{
[WebMethod]
public string sayHello(string name)
{
return "Hello" +name;

2ress &B to test the above -eb service+ the follo-ing output -ill be displayed
1lic8 on Service 'escription hyperlin8 to generate the follo-ing 0SD1 !2);m(nt for the above (eb
Service.
<?xml version="1.0" encoding="utf-8" ?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://tempuri.org/"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:soap1="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:!ttp="http://schemas.xmlsoap.org/wsdl/http/"
target"amespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:t#pes>
<s:sc!ema element$orm%efault="qualified" target"amespace="http://tempuri.org/">
<s:element name="sa!ello">
<s:complex&#pe>
s:se'uence>
<s:element min(ccurs="0" max(ccurs="1" name="name" t#pe="s:string" )>
<)s:se'uence>
<)s:complex&#pe>
<)s:element>
<s:element name="sa!ello"esponse">
<s:complex&#pe>
<s:se'uence>
<s:element min(ccurs="0" max(ccurs="1" name="sa!ello"esult" t#pe="s:string" )>
<)s:se'uence>
<)s:complex&#pe>
<)s:element>
<)s:sc!ema>
<)wsdl:t#pes>
<wsdl:message name="sa!elloSoap#n">
<wsdl:part name="parameters" element="tns:sa!ello" )>
<)wsdl:message>
<wsdl:message name="sa!elloSoap$ut">
<wsdl:part name="parameters" element="tns:sa!ello"esponse" )>
<)wsdl:message>
<wsdl:port&#pe name="Ser%ice1Soap">
<wsdl:operation name="sa!ello">
<wsdl:input message="tns:sa!elloSoap#n" )>
<wsdl:output message="tns:sa!elloSoap$ut" )>
<)wsdl:operation>
<)wsdl:port&#pe>
<wsdl:*inding name="Ser%ice1Soap" t#pe="tns:Ser%ice1Soap">
<soap:*inding transport="http://schemas.xmlsoap.org/soap/http" )>
<wsdl:operation name="sa!ello">
<soap:operation soap+ction="http://tempuri.org/sa!ello" st#le="document" )>
<wsdl:input>
<soap:*od# use="literal" )>
<)wsdl:input>
<wsdl:output>
<soap:*od# use="literal" )>
<)wsdl:output>
<)wsdl:operation>
<)wsdl:*inding>
<wsdl:*inding name="Ser%ice1Soap12" t#pe="tns:Ser%ice1Soap">
<soap1:*inding transport="http://schemas.xmlsoap.org/soap/http" )>
<wsdl:operation name="sa!ello">
<soap1:operation soap+ction="http://tempuri.org/sa!ello" st#le="document" )>
<wsdl:input>
<soap1:*od# use="literal" )>
<)wsdl:input>
<wsdl:output>
<soap1:*od# use="literal" )>
<)wsdl:output>
<)wsdl:operation>
<)wsdl:*inding>
<wsdl:service name="Ser%ice1">
<wsdl:port name="Ser%ice1Soap" *inding="tns:Ser%ice1Soap">
<soap:address location="http://localhost:1&'(/Ser%ice1.asmx" )>
<)wsdl:port>
<wsdl:port name="Ser%ice1Soap12" *inding="tns:Ser%ice1Soap12">
<soap1:address location="http://localhost:1&'(/Ser%ice1.asmx" )>
<)wsdl:port>
<)wsdl:service>
<)wsdl:definitions>
-# 0rit( a 8r2gram th( s(r7i)( 8r27i!(r )an 6( im8"(m(nt a sing"( g(t 8ri)((), stati) 6in!() an! g(t
8r2!;)t 28(rati2n#
SOAP
S.52 stands for Simple .b<ect 5ccess 2rotocol
S.52 is a communication protocol
S.52 is for communication bet-een applications
S.52 is a format for sending messages
S.52 communicates via 4nternet
S.52 is platform independent
S.52 is language independent
S.52 is based on ;M%
S.52 is simple and extensible
S.52 allo-s you to get around fire-alls
S.52 is a (#1 recommendation
SOAP B;i"!ing B"2)<s
5 S.52 message is an ordinary ;M% document containing the follo-ing elements7
?nvelope ( Mandatory )
'efines the start and the end of the message. 5n element that identifies the ;M% document as a
S.52 message
Header ( Optional )
1ontains any optional attributes of the message used in processing the message+ either at an
intermediary point or at the ultimate end point. 5 element that contains header information
=ody ( Mandatory )
1ontains the ;M% data comprising the message being sent. 5 =ody element that contains call and
response information
&ault ( Optional )
5n optional &ault element that provides information about errors that occurred -hile processing the
message 5 &ault element containing errors and status information
SyntaB R;"(s
Here are some important syntax rules7
5 S.52 message M3ST be encoded using ;M%
5 S.52 message M3ST use the S.52 ?nvelope namespace
5 S.52 message M3ST use the S.52 ?ncoding namespace
5 S.52 message must N.T contain a 'T' reference
5 S.52 message must N.T contain ;M% 2rocessing 4nstructions
S<("(t2n SOAP (ssag(
(42ml %ersion,"&"5"4)
(soap-6n%elope
2mlns-soap,"http-''777"78"org'955&'&9'soap:en%elope"
soap-encoding!tyle,"http-''777"78"org'955&'&9'soap:encoding")
(soap-Header)
"""
('soap-Header)
(soap-.ody)
"""
(soap-;ault)
"""
('soap-;ault)
('soap-.ody)
('soap-6n%elope)
,ODE :
g(t8ri)(()
pac8age com.ecerami.soap.examples>

import <ava.util.Hashtable>
/CC
C 5 Sample S.52 Service
C 2rovides 1urrent 2rice for re,uested Stoc88eeping 3nit )SD3*
C/
public class 2riceService E
protected Hashtable products>

/C Fero 5rgument 1onstructor %oad product database -ith t-o sample products C/
public 2riceService ) * E
products G ne- Hashtable) *>
// 0ed Hat %inux
products.put)65#BH"HB6+ ne- 'ouble )B$.II**>
// Mc5fee 2J2 2ersonal 2rivacy
products.put)65#BHBKB6+ ne- 'ouble )"I.II**>
L

/C
2rovides 1urrent 2rice for re,uested SD3 4n a real/setup+ this method -ould connect to a price database. 4f
SD3 is not found+ method -ill thro- a 2rice?xception. C/
public double get2rice )String s8u*
thro-s 2roductNot&ound?xception E
'ouble price G )'ouble* products.get)s8u*>
if )price GG null* E
thro- ne- 2roductNot&ound?xception )6SD37 6Ms8uM6 not found6*>
L
return price.doubleAalue) *>
L
L
To generate a (S'% file for this class+ run the follo-ing command7
<ava-sdl com.ecerami.soap.examples.2riceService /s /e http7//localhost7
H!H!/soap/servlet/rpcrouter /n urn7examples7priceservice
The :s option directs J%3? to create a S.52 binding> the :e option specifies the address of our service>
and the :n option specifies the namespace 30N for the service. J%3? -ill generate a PriceService.wsdl file.
G(t8r2!;)t()
NOxml versionG6".!6 encodingG63T&/H6OP
Ndefinitions nameG62roductService6
targetNamespaceG6http7//---.ecerami.com/-sdl/2roductService.-sdl6
xmlnsG6http7//schemas.xmlsoap.org/-sdl/6
xmlns7soapG6http7//schemas.xmlsoap.org/-sdl/soap/6
xmlns7tnsG6http7//---.ecerami.com/-sdl/2roductService.-sdl6
xmlns7xsdG6http7//---.-#.org/!!"/;M%Schema6
xmlns7xsd"G6http7//---.ecerami.com/schema6P

NtypesP
Nxsd7schema
targetNamespaceG6http7//---.ecerami.com/schema6
xmlnsG6http7//---.-#.org/!!"/;M%Schema6P
Nxsd7complexType nameG6product6P
Nxsd7se,uenceP
Nxsd7element nameG6name6 typeG6xsd7string6/P
Nxsd7element nameG6description6 typeG6xsd7string6/P
Nxsd7element nameG6price6 typeG6xsd7double6/P
Nxsd7element nameG6SD36 typeG6xsd7string6/P
N/xsd7se,uenceP
N/xsd7complexTypeP
N/xsd7schemaP
N/typesP

Nmessage nameG6get2roduct0e,uest6P
Npart nameG6s8u6 typeG6xsd7string6/P
N/messageP

Nmessage nameG6get2roduct0esponse6P
Npart nameG6product6 typeG6xsd"7product6/P
N/messageP

NportType nameG62roduct_2ortType6P
Noperation nameG6get2roduct6P
Ninput messageG6tns7get2roduct0e,uest6/P
Noutput messageG6tns7get2roduct0esponse6/P
N/operationP
N/portTypeP

Nbinding nameG62roduct_=inding6 typeG6tns72roduct_2ortType6P
Nsoap7binding styleG6rpc6
transportG6http7//schemas.xmlsoap.org/soap/http6/P
Noperation nameG6get2roduct6P
Nsoap7operation soap5ctionG6urn7examples7productservice6/P
NinputP
Nsoap7body
encodingStyleG6http7//schemas.xmlsoap.org/soap/encoding/6
namespaceG6urn7examples7productservice6
useG6encoded6/P
N/inputP
NoutputP
Nsoap7body
encodingStyleG6http7//schemas.xmlsoap.org/soap/encoding/6
namespaceG6urn7examples7productservice6 useG6encoded6/P
N/outputP
N/operationP
N/bindingP

Nservice nameG62roduct_Service6P
Nport nameG62roduct_2ort6 bindingG6tns72roduct_=inding6P
Nsoap7address locationG6http7//localhost7H!H!/soap/servlet/rpcrouter6/P
N/portP
N/serviceP
N/definitionsP
+# 0rit( a 8r2gram t2 im8"(m(nt th( 28(rati2n )an r()(i7( r(F;(st an! ?i"" r(t;rn a
r(s82ns( in t?2 ?ays#
a* .ne/(ay operation
b* 0e,uest Q 0esponse
(ssag( Patt(rns in 0SD1
The message pattern for a given operation by evaluating the pattern of @inputR and @output @ messages for the
operation in the service (S'% file. =ased on this analysis+ it generates code appropriate to the message
patterns being used
Th( R(F;(st$R(s82ns( Patt(rn
The re,uest/response operation includes one input element+ -hich is the client9s re,uest to the server+
follo-ed by one output element+ -hich is the server9s response bac8 to the client.
Figure 1: The Request-response message pattern
The One Way Pattern
The one/-ay operation includes one input element+ -hich is the client9s re,uest to the server. No response is
expected.
Figure 2: The One-wa message pattern
The Notification Pattern
The notification operation includes one output element+ -hich is the server9s message to the client.
Figure !: The "oti#i$ation message pattern
The Soicit-!es"onse Pattern
The solicit/response operation includes one output element+ -hich is the server9s re,uest to the client+
follo-ed by one input element+ -hich is the client9s response bac8 to the server.
Figure %: The &oli$it-response message pattern
The re,uest/response and the solicit/response patterns are generally synchronous+ as their usage usually
assumes that the re,uestor -ill receive an immediate response.
The one/-ay and the notification patterns are inherently asynchronous in that the re,uestor expects no
response.
,ODE :
+ a) On($0ay 28(rati2n
NOxml versionG6".!6OP
Ndefinitions nameG6Stoc8Suote6
targetNamespaceG6http7//example.com/stoc8,uote.-sdl6
xmlns7tnsG6http7//example.com/stoc8,uote.-sdl6
xmlns7xsd"G6http7//example.com/stoc8,uote.xsd6
xmlns7soapG6http7//schemas.xmlsoap.org/-sdl/soap/6
xmlnsG6http7//schemas.xmlsoap.org/-sdl/6P
Nmessage nameG6SubscribeToSuotes6P
Npart nameG6body6 elementG6xsd"7SubscribeToSuotes6/P
G8art nam(HIs;6s)ri6(h(a!(rI ("(m(ntHIBs!':S;6s)ri8ti2nH(a!(rIJK
N/messageP
NportType nameG6Stoc8Suote2ortType6P
Noperation nameG6SubscribeToSuotes6P
Ninput messageG6tns7SubscribeToSuotes6/P
N/operationP
N/portTypeP
Nbinding nameG6Stoc8SuoteSoap6 typeG6tns7Stoc8Suote2ortType6P
Gs2a8:6in!ing sty"(HI!2);m(ntI trans82rtHIhtt8:JJ(Bam8"(#)2mJsmt8IJK
Noperation nameG6SubscribeToSuotes6P
Ninput messageG6tns7SubscribeToSuotes6P
Gs2a8:62!y 8artsHI62!yI ;s(HI"it(ra"IJK
Gs2a8:h(a!(r m(ssag(HItns:S;6s)ri6(T2L;2t(sI 8artHIs;6s)ri6(h(a!(rI
;s(HI"it(ra"IJK
N/inputP
N/operationP
N/bindingP
Nservice nameG6Stoc8SuoteService6P
Nport nameG6Stoc8Suote2ort6 bindingG6tns7Stoc8SuoteSoap6P
Gs2a8:a!!r(ss "2)ati2nHImai"t2:s;6s)ri6(M(Bam8"(#)2mIJK
N/portP
N/serviceP
NtypesP
Nschema targetNamespaceG6http7//example.com/stoc8,uote.xsd6
xmlnsG6http7//---.-#.org/!!!/"!/;M%Schema6P
Nelement nameG6SubscribeToSuotes6P
NcomplexTypeP
NallP
Nelement nameG6tic8erSymbol6 typeG6string6/P
N/allP
N/complexTypeP
N/elementP
Nelement nameG6SubscriptionHeader6 typeG6uri0eference6/P
N/schemaP
N/typesP
N/definitionsP
+ 6) R(F;(st$R(s82ns(#
public class My(eb0e,uest
E
private (eb0e,uest re,uest>
private Stream dataStream>

private string status>
public String Status
E
get
E
return status>
L
set
E
status G value>
L
L
public My(eb0e,uest)string url*
E
// 1reate a re,uest using a 30% that can receive a post.
re,uest G (eb0e,uest.1reate)url*>
L
public My(eb0e,uest)string url+ string method*
7 this)url*
E
if )method.?,uals)6J?T6* TT method.?,uals)62.ST6**
E
// Set the Method property of the re,uest to 2.ST.
re,uest.Method G method>
L
else
E
thro- ne- ?xception)64nvalid Method Type6*>
L
L
public My(eb0e,uest)string url+ string method+ string data*
7 this)url+ method*
E
// 1reate 2.ST data and convert it to a byte array.
string post'ata G data>
byteUV byte5rray G ?ncoding.3T&H.Jet=ytes)post'ata*>
// Set the 1ontentType property of the (eb0e,uest.
re,uest.1ontentType G 6application/x/---/form/urlencoded6>
// Set the 1ontent%ength property of the (eb0e,uest.
re,uest.1ontent%ength G byte5rray.%ength>
// Jet the re,uest stream.
dataStream G re,uest.Jet0e,uestStream)*>
// (rite the data to the re,uest stream.
dataStream.(rite)byte5rray+ !+ byte5rray.%ength*>
// 1lose the Stream ob<ect.
dataStream.1lose)*>
L
public string Jet0esponse)*
E
// Jet the original response.
(eb0esponse response G re,uest.Jet0esponse)*>
this.Status G ))Http(eb0esponse*response*.Status'escription>
// Jet the stream containing all content returned by the re,uested server.
dataStream G response.Jet0esponseStream)*>
// .pen the stream using a Stream0eader for easy access.
Stream0eader reader G ne- Stream0eader)dataStream*>
// 0ead the content fully up to the end.
string response&romServer G reader.0eadTo?nd)*>
// 1lean up the streams.
reader.1lose)*>
dataStream.1lose)*>
response.1lose)*>
return response&romServer>
L
L
/# 0rit( a 8r2gram t2 im8"(m(nt t2 )r(at( a sim8"( ?(6 s(r7i)( that )2n7(rts th( t(m8(rat;r( 9r2m
Fahr(nh(it t2 ,("si;s (;sing HTTP P2st Pr2t2)2")
,ODE :
S(r7i)('#asmB#)s
using System>
using System.1ollections.Jeneric>
using System.(eb>
using System.(eb.Services>
namespace (ebService
E
/// NsummaryP
/// Summary description for Service"
/// N/summaryP
U(ebService)Namespace G 6http7//tempuri.org/6*V
U(ebService=inding)1onformsTo G (si2rofiles.=asic2rofile"_"*V
USystem.1omponentModel.Toolbox4tem)false*V
public class Service" 7 System.(eb.Services.(ebService
E
U(ebMethodV
public string &ahrenheitTo1elsius)string &ahrenheit*
E
ob<ect fahr G null>
fahr G &ahrenheit.0eplace)6+6+ 6.6*.Trim)9 9*>
if )fahr GG 66*
E
return 6?rror6>
L
int returnAal G ))))1onvert.To4nt#)fahr** / #* / I* C B*>
return returnAal.ToString)*>
L
U(ebMethodV
public int 1elsiusTo&ahrenheit)string 1elsius*
E
ob<ect cel G null>
cel G 1elsius>
//cel G 1elsius.0eplace)6+6+ 6.6*.Trim)9 9*>
int returnAal G 1onvert.To4nt#))))1onvert.To4nt#)cel** C I* / B* M #*>
return returnAal>
L
L
L
%# 0rit( a 8r2gram t2 im8"(m(nt 6;sin(ss UDDI R(gistry (ntry
Intr2!;)ti2n t2 UDDI
3''4 is a platform/independent frame-or8 for describing services+ discovering businesses+ and integrating
business services by using the 4nternet.
3''4 stands for 3niversal 'escription+ 'iscovery and 4ntegration
3''4 is a directory for storing information about -eb services
3''4 is a directory of -eb service interfaces described by (S'%
3''4 communicates via S.52
3''4 is built into the Microsoft .N?T platform
UDDI Benefits
5ny industry or businesses of all si:es can benefit from 3''4.
=efore 3''4+ there -as no 4nternet standard for businesses to reach their customers and partners -ith
information about their products and services. Nor -as there a method of ho- to integrate into each other9s
systems and processes.
3''4 specification can help to solve7
Ma8ing it possible to discover the right business from the millions currently online
'efining ho- to enable commerce once the preferred business is discovered
0eaching ne- customers and increasing access to current customers
?xpanding offerings and extending mar8et reach
Solving customer/driven need to remove barriers to allo- for rapid participation in the global 4nternet
economy
'escribing services and business processes programmatically in a single+ open+ and secure
environment
UDDI )2nsists 29 t?2 8arts
&irst+ 3''4 is a technical specification for building a distributed directory of businesses and -eb
services. 'ata is stored -ithin a specific ;M% format+ and the 3''4 specification includes 524
details for searching existing data and publishing ne- data.
Second+ the 3''4 =usiness 0egistry )also fre,uently referred to as the 3''4 6cloud services6* is a
fully operational implementation of the 3''4 specification. %aunched in May !!" by Microsoft and
4=M+ the 3''4 registry no- enables anyone to search existing 3''4 data. 4t also enables any
company to register itself and its services.
The data captured -ithin 3''4 is divided into three main categories7
White pages
This includes general information about a specific company / for example+ business name+ business
description+ contact information+ address and phone numbers. 4t can also include uni,ue business identifiers+
such as a 'un W =radstreet '/3/N/SX Number.
Yellow pages
This includes general classification data for either the company or the service offered. &or example+ this data
may include industry+ product+ or geographic codes based on standard taxonomies.
Green pages
This category contains technical information about a -eb service. Jenerally+ this includes a pointer to an
external specification and an address for invo8ing the -eb service. 3''4 is not restricted to describing -eb
services based on S.52. 0ather+ 3''4 can be used to describe any service+ from a single -eb page or email
address all the -ay up to S.52+ 1.0=5+ and Yava 0M4 services.
,ODE :
,r(ating UDDI R(gistry
2.ST /save_business HTT2/"."
Host7 ---.;YF.com
1ontent/Type7 text/xml> charsetG6utf/H6
1ontent/%ength7 nnnn
S.525ction7 6save_business6
NOxml versionG6".!6 encodingG63T&/H6 OP
N?nvelope xmlnsG6http7//schemas/xmlsoap.org/soap/envelope/6P
N=odyP
Nsave_business genericG6.!6 xmlnsG6urn7uddi/org7api_v6P
NbusinessDeyG66P
N/businessDeyP
NnameP
;YF+ 2vt %td.
N/nameP
NdescriptionP
1ompany is involved in giving Stat/of/the/art....
N/descriptionP
Nidentifier=agP ... N/identifier=agP
...
N/save_businessP
N/=odyP
N/?nvelopeP
?xample of ho- 3''4 and (S'% -or8 together. Here is the NtModelP for this -eb service7
NtModel authori:edNameG6...6 operatorG6...6 tModelDeyG6...6P
NnamePHert:0eserveServiceN/nameP
Ndescription xml7langG6en6P
(S'% description of the Hert: reservation service interface
N/descriptionP
Novervie-'ocP
Ndescription xml7langG6en6P
(S'% source document.
N/descriptionP
Novervie-30%P
http7//mach#.ebphost.net/-sdl/hert:_reserve.-sdl
N/overvie-30%P
N/overvie-'ocP
Ncategory=agP
N8eyed0eference
tModelDeyG6uuid71"51&K'/IKZ/$$!$/I'Z!/#I=ZBK?K5=$6
8eyNameG6uddi/org7types6 8eyAalueG6-sdlSpec6/P
N/category=agP
N/tModelP
4# 0rit( a 8r2gram t2 im8"(m(nt
a) 0(6 6as(! s(r7i)( )2ns;m(r
6) 0in!2?s a88"i)ati2n 6as(! ?(6 s(r7i)( )2ns;m(r
a) Web based service consumer
,r(ating a 0(6 S(r7i)(
Tas< ' = ,r(ating a 0(6 S(r7i)(
Navigate to Start > Pr2grams > i)r2s29t Vis;a" St;!i2# NET -&'& > i)r2s29t Vis;a" St;!i2
#NET -&'&
Select Fi"(> N(? > Pr2@()t menu command
4n the 2ro<ect Types pane select Vis;a" ,A Pr2@()ts
4n the Templates pane+ clic8 ASP#NET 0(6 S(r7i)(
1lic8 OK
Tas< - = EB82sing a (th2! as a 0(6 S(r7i)(
Navigate to the Service".asmx file in S2";ti2n EB8"2r(r+ right/clic8 the file and select Vi(? ,2!(
1reate a ne- function called sayH(""2+ -hich ta8es a string parameter and returns a string
4mplement the method to return the result
5dd the C0(6(th2!()D attribute to the function. This attribute tells .N?T to expose the function as a
(eb Service.
#!e$%ethod&
pu$lic int 'dd(int ')int $*
+
return ',$-
.
Tas< + = P(r92rm Initia" T(sting
0ight/clic8 Service".asmx in the S2";ti2n EB8"2r(r and clic8 S(t as Start Pag(
To compile your application press ,TR1EF%
Aisual Studio .N?T opens a (eb page+ to test the (eb Service -ithout implementing a specific client.
To vie- the test page+ clic8 the a!! lin8.
To invo8e the (eb Service from the test page+ enter a+ b values in the T(Bt 62B(s and clic8 In72<(.
=elo- is a sample result
<?xml version="1.0" encoding="utf-8" ?>
<int xmlns="http://tempuri.org/">/0</int>
,r(at( a ?(6 a88"i)ati2n t2 ,2ns;m( th( a627( ?(6 s(r7i)( as 92""2?s#
Tas< ' = ,r(ating a 0(6 A88"i)ati2n
Navigate to Start > Pr2grams > i)r2s29t Vis;a" St;!i2# NET -&'& > i)r2s29t Vis;a" St;!i2
#NET -&'&
Select Fi"(> N(? > Pr2@()t menu command
4n the 2ro<ect Types pane select Vis;a" ,A Pr2@()ts
4n the Templates pane+ clic8 ASP#NET 0(6 A88"i)ati2n
1lic8 OK
D(sign St(8s :
4n the design -indo- ta8e t-o labels and t-o text boxes and one button
Set "a6"(' text property to enter a value
Set "a6"(- text property to enter b value
Set 6;tt2n ext property to add
'ouble 1lic8 on add button
1ode -indo- -ill be opened and in the button"_clic8 event -rite the follo-ing code
using System>
using System.1ollections.Jeneric>
using System.(eb>
using System.(eb.34>
using System.(eb.34.(eb1ontrols>
using (ebService#>
namespace (eb5pplication#
E
public partial class _'efault 7 System.(eb.34.2age
E
protected void button"_1lic8)ob<ect sender+ ?vent5rgs e*
E
Service" s"Gne- Service")*>
int aG1onvert.To4nt#)Text=ox".Text*>
int bG1onvert.To4nt#)Text=ox.Text*>
%abel".TextG6The sum of a and b is6M1onvert.ToString)s".add)a+b**>
L
L
L
2ress &B to 03N the above (eb 5pplication.
4 B) T 2 )2ns;m(J;s( a ?(6 s(r7i)( in a ?in!2?s a88"i)ati2n#
&irst -e should have a -eb service+ so let9s create a simple -eb service. 1reate an 5S2.N?T (eb Service
page and modify the code as given below.
using System>
using System.1ollections.Jeneric>
using System.%in,>
using System.(eb>
using System.(eb.Services>
U(ebService)Namespace G 6http7//tempuri.org/6*V
U(ebService=inding)1onformsTo G (si2rofiles.=asic2rofile"_"*V
// To allo- this (eb Service to be called from script+ using 5S2.N?T 5Y5;+ uncomment the follo-ing line.
// USystem.(eb.Script.Services.ScriptServiceV
public class Service 7 System.(eb.Services.(ebService
E
public Service )* E
//3ncomment the follo-ing line if using designed components
//4nitiali:e1omponent)*>
L
U(ebMethod)'escriptionG6Sho- Message6*V
public string msgsho-)*
E return 6Hello+ (eb Service...6>
L
U(ebMethod)'escriptionG65ddition .f T-o 4ntegers6*V
public int add)int a+ int b*
E
return a M b>
L
L
0un the service.
O;t8;t :
To consume the -eb service in a -indo-s form application+ follo- the given steps.
1reate a (indo-s &orm 5pplication.
Jo to Solution ?xplorer and right clic8 on your pro<ect. 5 pop/up menu -ill open.
Select 5dd Service 0eference. 5 ne- -indo- -ill open li8e the belo- figure.

1lic8 on 5dvanced ) %oo8 at above figure*. 5 ne- -indo- -ill open li8e the belo- figure.
1lic8 on 5dd (eb 0eference.
1opy the 30% of your running -eb service and paste it at the 30% )%oo8 at the above figure.* and
1lic8 the Jo button. 5 ne- -indo- -ill open li8e the belo- figure.
1lic8 5dd 0eference. No- Service 0eference has been added to your pro<ect. 1reate some controls
on the design page and -rite code to call the methods of your -eb service.
using System>
using System.1ollections.Jeneric>
using System.1omponentModel>
using System.'ata>
using System.'ra-ing>
using System.%in,>
using System.Text>
using System.(indo-s.&orms>
namespace consuming-ebservice
E
public partial class &orm" 7 &orm
E
public &orm")*
E
4nitiali:e1omponent)*>
L
private void btnadd_1lic8)ob<ect sender+ ?vent5rgs e*
E
localhost.Service ob< G ne- localhost.Service)*>
txtresult.Text G ob<.add)1onvert.To4nt#)txtfirstno.Text*+
1onvert.To4nt#)txtsecondno.Text**.ToString)*>
L
private void btnmsgsho-_1lic8)ob<ect sender+ ?vent5rgs e*
E
localhost.Service ob< G ne- localhost.Service)*>
Message=ox.Sho-)ob<.msgsho-)**>
L
L
L
You can -rite the same code in another -ay by adding NameSpace as
*2;rPr2@()tNam(#0(6r(9(r(n)(nam(. %oo8 belo- the full code for this example after adding namespace.
using System>
using System.1ollections.Jeneric>
using System.1omponentModel>
using System.'ata>
using System.'ra-ing>
using System.%in,>
using System.Text>
using System.(indo-s.&orms>
using )2ns;ming?(6s(r7i)(#"2)a"h2stN
namespace consuming-ebservice
E
public partial class &orm" 7 &orm
E
public &orm")*
E
4nitiali:e1omponent)*>
L
private void btnadd_1lic8)ob<ect sender+ ?vent5rgs e*
E
localhost.Service ob< G ne- localhost.Service)*>
txtresult.Text G ob<.add)1onvert.To4nt#)txtfirstno.Text*+
1onvert.To4nt#)txtsecondno.Text**.ToString)*>
L
private void btnmsgsho-_1lic8)ob<ect sender+ ?vent5rgs e*
E
Service ob< G ne- Service)*>
Message=ox.Sho-)ob<.msgsho-)**>
L
L
L
0un the -indo-s application.
O;t8;t:
(rite the first and second number and clic8 the 65dd6 button.
1lic8 the 6Message Sho-6 button.

Вам также может понравиться