In its simplest form, a Web service is a Remote Procedure Call (RPC). In other words, it is a method invocation across a process boundary. That is the extent of the similarities between a Web service and a standard RPC. What differentiates Web services is that the call is made using the Hypertext Transfer Protocol (HTTP) and the request is made and received using the Simple Object Access Protocol (SOAP) format. This format is essentially an Extensible Markup Language (XML)-like document format, as shown in Listing 11-1.
Listing 11-1: A Web Service Request in SOAP Format
POST /webservice1/service1.asmx HTTP/1.1 Host: localhost Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://tempuri.org/GetAllEmployees" <?xml version="1.0" encoding="utf-8"?> <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> <GetAllEmployees xmlns="http://tempuri.org/" /> </soap:Body> </soap:Envelope>
This is a sample of what the SOAP request would look like if you needed to create the SOAP data to send to the Web service yourself.
Note | What makes XML Web services so powerful is that anybody who can write a properly formatted SOAP message can call a Web service. You do not need to use a powerful language such as C#, Visual Basic, or Java. This is what makes Web services a "universal" way of sending and receiving data. Anything that can process text can send and receive SOAP messages. |
The part of the SOAP message to note in Listing 11-1 is the SOAP body tag, which contains the actual call to the GetAllEmployees method. You will walk through creating this Web service later in this chapter (in the "Creating the GetAllEmployees Web Service" section). Listing 11-2 shows an example of the SOAP response format that will be returned by the method call.
Listing 11-2: The SOAP Response Format
HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <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> <GetAllEmployeesResponse xmlns="http://tempuri.org/"> <GetAllEmployeesResult> <xsd:schema>schema</xsd:schema>xml</GetAllEmployeesResult> </GetAllEmployeesResponse> </soap:Body> </soap:Envelope>
This shows the format in which the SOAP response will be encoded. Again, the important thing to note is the SOAP body tag. The GetAllEmployeeResult tag contains an XML Schema Definition (XSD) schema tag and the word xml. This denotes that the returned value will contain an XSD, followed by the XML that contains your employee data.