30.07.2013 Views

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

1036 ASP .<strong>NET</strong> and Web Services Chapter 21<br />

Testing and Debugging Tip 21.1<br />

Using the ASMX page of a Web service <strong>to</strong> test and debug methods makes that Web service<br />

more reliable and robust; it also reduces the likelihood that others who use the Web service<br />

will encounter errors. 21.1<br />

21.3 Simple Object Access Pro<strong>to</strong>col (SOAP) and Web Services<br />

Simple Object Access Pro<strong>to</strong>col (SOAP) is a platform-independent pro<strong>to</strong>col that uses XML <strong>to</strong><br />

make remote procedure calls over HTTP. Each call and response is packaged in a SOAP<br />

message—an XML message containing all the information necessary <strong>to</strong> process its contents.<br />

SOAP messages are quite popular, because they are written in the easy-<strong>to</strong>-understand<br />

and platform-independent XML. Similarly, HTTP was chosen <strong>to</strong> transmit SOAP messages<br />

because HTTP is a standard pro<strong>to</strong>col for sending information across the Internet. The use<br />

of XML and HTTP enables different operating systems <strong>to</strong> send and receive SOAP messages.<br />

Another benefit of HTTP is that it can be used with networks that contain firewalls—<br />

security barriers that restrict communication among networks.<br />

Another reason that programmers creating Web services use SOAP is its extensive<br />

set of supported data types. Readers should note that the wire format used <strong>to</strong> transmit<br />

requests and responses must support all data types passed between the applications. Web<br />

services that use SOAP support a wider variety of data types than do Web services that<br />

employ other wire formats. The data types supported by SOAP include the basic data<br />

types, DataSet, DateTime, XmlNode and several others. SOAP also permits transmission<br />

of arrays of all these types. In addition, user-defined types can be used; we demonstrate<br />

how <strong>to</strong> do this in Section 21.8.<br />

ASP .<strong>NET</strong> Web services send requests and responses <strong>to</strong> and from Web services via<br />

SOAP. When a program invokes a Web-service method, the request and all relevant information<br />

is packaged in a SOAP request message and sent <strong>to</strong> the appropriate destination.<br />

When the Web service receives this SOAP message, it begins <strong>to</strong> process the contents called<br />

the SOAP envelope, which specifies the method that the client wishes <strong>to</strong> execute and the<br />

arguments the client is passing <strong>to</strong> that method. After the Web service receives this request<br />

and parses it, the proper method is called with the specified arguments (if there are any),<br />

and the response is sent back <strong>to</strong> the client in a SOAP response message. The client parses<br />

the response <strong>to</strong> retrieve the result of the method call.<br />

The SOAP response message portrayed in Fig. 21.5 was taken directly from the<br />

Bigger method of the HugeInteger Web service (Fig. 21.3). This Web service provides<br />

programmers with several methods that manipulate integers larger than those that can<br />

be s<strong>to</strong>red as a Long variable. Most programmers do not manipulate SOAP messages,<br />

allowing the Web service <strong>to</strong> handle the details of transmission.<br />

1 POST /HugeInteger/HugeInteger.asmx HTTP/1.1<br />

2 Host: localhost<br />

3 Content-Type: text/xml; charset=utf-8<br />

4 Content-Length: length<br />

5 SOAPAction: "http://www.deitel.com/Bigger"<br />

6<br />

Fig. 21.5 SOAP request message for the HugeInteger Web service (part 1 of 2).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!