Deitel & Associates, Inc. Logo

Back to www.deitel.com
digg.png delicious.png blinkit.png furl.png
Visual C# 2005 How to Program, 2/e
Visual C# 2005 How to Program, 2/e

ISBN:
0-13-152523-9
© 2006
pages: 1535

Order
Amazon logo

[Note: This is an excerpt (Sections 22.1–22.4) of Chapter 22, Web Services, from our textbook Visual C# 2005 How to Program, 2/e. These articles may refer to other chapters or sections of the book that are not included here. Permission Information: Deitel, Harvey M. and Paul J., VISUAL C# 2005 HOW TO PROGRAM, 2/E, 2005, pp.1164–1190. Electronically reproduced by permission of Pearson Education, Inc., Upper Saddle River, New Jersey.]
Simple Object Access Protocol (SOAP)
 
The Simple Object Access Protocol (SOAP) is a platform-independent protocol that uses XML to make remote procedure calls, typically over HTTP. Each request and response is packaged in a SOAP message-an XML message containing the information that a Web service requires to process the message. SOAP messages are written in XML so that they are human readable and platform independent. Most firewalls-security barriers that restrict communication among networks-do not restrict HTTP traffic. Thus, XML and HTTP enable computers on different platforms to send and receive SOAP messages with few limitations.
Web services also use SOAP for the extensive set of types it supports. The wire format used to transmit requests and responses must support all types passed between the applications. SOAP types include the primitive types (e.g., Integer), as well as DateTime, XmlNode and others. SOAP can also transmit arrays of all these types. In addition, DataSets can be serialized into SOAP. In Section 22.7, you will see that you can transmit user-defined types in SOAP messages.
When a program invokes a Web method, the request and all relevant information are packaged in a SOAP message and sent to the server on which the Web service resides. When the Web service receives this SOAP message, it begins to process the contents (contained in a SOAP envelope), which specify the method that the client wishes to execute and any arguments the client is passing to that method. This process of interpreting a SOAP message's contents is known as parsing a SOAP message. After the Web service receives and parses a request, the proper method is called with the specified arguments (if there are any), and the response is sent back to the client in another SOAP message. The client parses the response to retrieve the result of the method call.
The SOAP request in Fig. 22.8 was taken from the test page for the HugeInteger Web service's Bigger method (Fig. 22.4). Visual C# 2005 creates such a message when a client wishes to execute the HugeInteger Web service's Bigger method. If the client is a Web application, Visual Web Developer creates the SOAP message. The message in Fig. 22.8 contains placeholders (length in line 4 and string in lines 16-17) representing values specific to a particular call to Bigger. If this were a real SOAP request, elements first and second (lines 16-17) would each contain an actual value passed from the client to the Web service, rather than the placeholder string. For example, if this envelope were transmitting the request from Fig. 22.4, element first and element second would contain the numbers displayed in the figure, and placeholder length (line 4) would contain the length of the SOAP message. Most programmers do not manipulate SOAP messages directly, but instead allow the .NET framework to handle the transmission details.
Fig. 22.8 SOAP request message for the HugeInteger Web service. 
1   POST /HugeInteger/HugeInteger.asmx HTTP/1.1
2   Host: localhost
3   Content-Type: text/xml; charset=utf-8
4   Content-Length: length
5   SOAPAction: "http://www.deitel.com/Bigger"
6   
7   <?xml version="1.0" encoding="utf-8"?>
8   
9   <soap:Envelope
10      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
11      xmlns:xsd="http://www.w3.org/2001/XMLSchema"
12      xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
13   
14    <soap:Body>
15      <Bigger xmlns="http://www.deitel.com">
16         <first>string</first>
17         <second>string</second>
18      </Bigger>
19    </soap:Body>
20   </soap:Envelope>
Publishing and Consuming Web Services
This section presents several examples of creating (also known as publishing) and using (also known as consuming) Web services. Recall that an application that consumes a Web service actually consists of two parts-a proxy class representing the Web service and a client application that accesses the Web service via an instance of the proxy class. The instance of the proxy class passes a Web method's arguments from the client application to the Web service. When the Web method completes its task, the instance of the proxy class receives the result and parses it for the client application. Visual C# 2005 and Visual Web Developer create these proxy classes for you. We demonstrate this momentarily.
 
Page 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11

Tutorial Index