Locating Web Services Using the Discovery Process and the Web Services Directories

only for RuBoard

Web service discovery is the process of programmatically locating, or discovering, one or more related documents that describe a particular web service using the WSDL. Through this process, the web-service clients learn about the existence of a web service and the address of the web service's description document. The discovery process is enabled by a published .disco file, which is an XML document that contains links to other resources that describe the web service. The following code shows a sample structure of a .disco file that provides links to a news service and another stock-quote service on the same server:

 <?xml version="1.0" encoding="utf-8" ?>  <disco:discovery xmlns:disco="http://schemas.xmlsoap.org/disco/"xmlns:scl="http:// graphics/ccc.gif schemas.xmlsoap.org/disco/scl/">  <scl:contractRef ref="http//MyWebServer/MyWebServices/NewsService.asmx?wsdl"  docRef="http://MyWebServer/MyWebServices/NewsService.asmx" />  <scl:contractRef ref="http://MyWebServer/MyWebServices/ graphics/ccc.gif StockQuoteService.asmx?wsdl"docRef="http://MyWebServer/MyWebServices/ graphics/ccc.gif StockQuoteService.asmx" />  </disco:discovery> 

Web service directories provide central locations where web service providers can publish information about their available web services. So, a potential client application developer can easily locate an organization that provides web services for a particular purpose or determine what web services a particular organization provides.

Universal Description, Discovery, and Integration (UDDI) is an industry initiative to enable businesses to describe and publish their web services in a global registry. UDDI contains standards-based specifications for service description and discovery.

Understanding SOAP

You have already seen the benefits of using SOAP as a wire format for communication in a distributed system. The following paragraph is a formal definition of SOAP, as provided by the SOAP 1.1 Specification:

"SOAP provides a simple and lightweight mechanism for exchanging structured and typed information between peers in a decentralized, distributed environment using XML. SOAP does not itself define any application semantics such as a programming model or implementation specific semantics; rather it defines a simple mechanism for expressing application semantics by providing a modular packaging model and encoding mechanisms for encoding data within modules. This allows SOAP to be used in a large variety of systems ranging from messaging systems to RPC."

ASP.NET web services make the SOAP message transfers completely transparent to you. You are not required to learn the details of the SOAP message structure unless you want to customize the SOAP response that's sent to the client or intercept the SOAP request and response and alter them. Here, you look at the four main parts of the SOAP protocol specification:

  • The first part defines a mandatory extensible envelope for encapsulating data. The SOAP envelope defines a SOAP message; it's the basic unit of exchange between SOAP message processors. This is the only mandatory part of the specification. (This part refers to Section 4 of the SOAP 1.1 Specification.)

  • The second part defines optional data-encoding rules for representing application-defined data types and graphs of typed objects, and a uniform model for serializing data models that are independent of any language binding. (This part refers to Section 5 of the SOAP 1.1 Specification.)

  • The third part defines an RPC-style (request/response) message-exchange pattern. Each SOAP message is a one-way transmission. RPC is not limited to being a request/response mechanism. Web services often combine SOAP messages to implement such patterns, but SOAP does not mandate a message-exchange pattern. This part of the specification is optional. (This part refers to Section 7 of the SOAP 1.1 Specification.)

  • The fourth part defines a binding between SOAP and HTTP. However, this part is optional. You can use SOAP in combination with any transport protocol or mechanism that can transport the SOAP envelope, including SMTP or FTP. (This part refers to Section 6 of the SOAP 1.1 Specification.)

SOAP Envelope

The SOAP protocol follows the XML version 1.0 specification, which mandates the need for the single root XML element called Envelope . The following code shows a sample SOAP message with the root Envelope element containing the other elements, the optional Header and the mandatory Body elements:

 <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:xsd="http://www.w3.org/2001/XMLSchema"  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">    <soap:Header>       <!-- Optional SOAP Header. -->    </soap: Header >    <soap:Body>       <!-- Mandatory SOAP Body. Serialized object information -->    </soap:Body>  </soap:Envelope> 

The Envelope element in the preceding code includes the soap namespace pointing to the URL http://schemas.xmlsoap.org/soap/envelope/. All the SOAP elements and attributes use this namespace qualifier. Not providing this exact URL causes your SOAP message to be treated as a version error by the SOAP application.

You can see the SOAP Envelope schema defined at http://schemas.xmlsoap.org/soap/envelope/.

The SOAP encodingStyle global attribute can indicate the serialization rules used in a SOAP message. This attribute has the default value of http://schemas.xmlsoap.org/soap/encoding/.

SOAP Header

The optional Header element, if present, must appear as the first child of the root Envelope element. The Header element provides special information, such as authentication, transaction management, payment, and so on, to be processed by the recipient application. The following code shows a sample Header element that contains transaction information for an application:

 <soap:Header>     <t:Transaction        xmlns:t="some-URI" soap:mustUnderstand="1">            10     </t:Transaction>  </ soap:Header> 

The SOAP mustUnderstand global attribute in the Header element is used to indicate that the Header entry is mandatory for the recipient to process the SOAP message.

SOAP Body

The mandatory SOAP Body element can represent a request message that contains information about the method names and the method parameters. The following code shows a sample SOAP request message with the Body element that contains the method name GetQuote and the parameter symbol with the value MSFT :

 POST /mywebservices/StockQuoteService.asmx HTTP/1.1  Host: www.somedomain.com  Content-Type: text/xml; charset=utf-8  Content-Length: nnnn  SOAPAction: http://tempuri.org/GetQuote  <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:xsd="http://www.w3.org/2001/XMLSchema"  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">    <soap:Body>      <GetQuote xmlns="http://tempuri.org/">        <symbol>MSFT</symbol>      </GetQuote>    </soap:Body>  </soap:Envelope> 

The SOAP Body can also represent a SOAP response message that's returned from the server. This contains the data returned from a method call on the remote server object. The following code shows a sample SOAP response:

 HTTP/1.1 200 OK  Content-Type: text/xml; charset=utf-8  Content-Length: nnnn  <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:xsd="http://www.w3.org/2001/XMLSchema"  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">    <soap:Body>      <GetQuoteResponse xmlns="http://tempuri.org/">        <GetQuoteResult>69.5</GetQuoteResult>      </GetQuoteResponse>    </soap:Body>  </soap:Envelope> 

The Body element can contain a SOAP Fault element to return error information to the calling client. This element must be the first child of the Body element. The following is a sample SOAP message with the Fault element showing an application-specific error:

 <soap:Envelope    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">     <soap:Body>         <soap:Fault>             <faultcode> soap:Server</faultcode>             <faultstring>Server Error</faultstring>             <detail>  <e:myfaultdetails  xmlns:e='http://newriders.com/webservices/addressbook/faults' >              <message>Invalid User</message>              <errorcode>1001</errorcode>            </e:myfaultdetails>             </detail>         </soap:Fault>     </soap:Body>  </soap:Envelope> 

SOAP Encoding

The SOAP encoding rules define a serialization mechanism that can exchange instances of application-defined data types. Simple types and compound types are the main encoding data types found in a SOAP specification. SOAP's simple types include all the types found in the section "Built-In Datatypes" of the W3C XML Schema, Part 2: Datatypes Specification. Alternatively, a SOAP message can use the elements declared for every simple data type by the SOAP ENC schema and namespace. The following shows you an example:

 <SOAP-ENC:int  id="count">10</SOAP-ENC:int> 

SOAP provides support for different compound types, such as structures, generic compound data types, and arrays. The following code gives you an example of how a string array can be encoded in a SOAP message:

 <soap:Envelope   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xmlns:xsd="http://www.w3.org/2001/XMLSchema"   xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"   soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"   xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"  >   <soap:Body>      <GetSOAPAuthorsListResponse xmlns="http://tempuri.org/"       >             <AuthorListArray  href="#array"  />      </GetSOAPAuthorsListResponse>       <SOAP-ENC:Array  id="array"  SOAP-ENC:arrayType="xsd:string[8]">           <SOAP-ENC:string>Don Box</SOAP-ENC:string>           <SOAP-ENC:string>David Ehnebuske</SOAP-ENC:string>       <SOAP-ENC:string>Gopal Kakivaya</SOAP-ENC:string>           <SOAP-ENC:string>Andrew Layman</SOAP-ENC:string>           <SOAP-ENC:string>Noah Mendelsohn</SOAP-ENC:string>           <SOAP-ENC:string>Henrik Frystyk Nielsen</SOAP-ENC:string>           <SOAP-ENC:string>Satish Thatte</SOAP-ENC:string>           <SOAP-ENC:string>Dave Winer</SOAP-ENC:string>        </SOAP-ENC:Array>    </soap:Body>  </soap:Envelope> 

Other array types, such as sparse arrays, partially transmitted arrays, and multidimensional arrays, are also supported by the SOAP 1.1 Specification.

Note

You can view the SOAP version 1.1 specification at www.w3.org/TR/SOAP/ and version 1.2, which is a working draft at the time of writing, at www.w3.org/TR/soap12/.


only for RuBoard


XML and ASP. NET
XML and ASP.NET
ISBN: B000H2MXOM
EAN: N/A
Year: 2005
Pages: 184

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net