Author: Bilal Siddiqui (wap_monster@yahoo.com) CEO, WAP Monster01 Mar 2002
Translator: Mei Qingsong
Note: It is inevitable due to the error between time and my own level.
Simple Object Access Protocol (SOAP) provides a way to access remote objects. Such objects have JavaBean, EJB components, COM, and COM objects, and more. These objects use different companies and may be visible on the Internet. Therefore SOAP is a mechanism for exchanged enterprise information on the Internet. In this article, the author will discuss the details of SOAP communication, how to use SOAP to display its feature, how to call SOAP objects and how to exchange information in SOAP perception software. He will demonstrate how to publish the WSDL program in the first part as SOAP service, and its remote call.
One. SOAP and WSDL
I introduced WSDL in the first part of this series. WSDL describes the interface of the Web Service. The owner of the Web Service will use SOAP to implement these interfaces. Therefore, the WSDL service exists in the form of SOAP services. Once the Web Service user has a WSDL file, he knows the details of the interface, you can use SOAP to communicate with the Web Service.
You can view the Web Service you published by the WSDL interface as an object, which can be remotely accessed from the Internet via SOAP. Since services are objects, there must be some attributes to be related to each service and its behavior. The SOAP message is the XML file that may work on HTTP.
two. Reasons for using SOAP
B2B (Business-To-Business) and A2A (Application-to-Application) The instructions of both parties of the enterprise need to communicate to exchange their information. The concept of workflow is used in B2B and runs through business integration. For example, a company calls the supplier's service to meet the needs of our customers, which forms a vertical supply chain. Some suppliers will also expand the service of other enterprises in supply joint adjustment.
Obviously, this type of application is interactive. Any enterprise is just one end of SOAP communication, and the other end is implemented by other people on the Internet.
In the next few years, corporate integration and interaction capabilities will become a challenging task for software engineers and companies. Platform dependence will also be a big problem that integrates and interacting. SOAP is the easiest mechanism for realizing business integration and interaction capabilities.
three. SOAP architecture
After a preliminary understanding of SOAP and its role, I will discuss its architecture to understand the internal situation. In Figure Figure 1, you can see the following components to be used in a typical SOAP communication mechanism:
1. SOAP Client
2. SOAP Service
3. Actual Service
Figure 1. Components of a Typical SOAP Communication Architecture
The roles of each entity mentioned above in the architecture will be discussed below.
SOAP Client
The SOAP Client is a SOAP perceived machine that produces SOAP requests and sends SOAP requests to SOAP Server via HTTP. The SOAP Client is a SOAP message. Generally speaking, there are two SOAP messages: SOAP Client sends a SOAP request message for SOAP Service and SOAP Service to SOAP response messages for SOAP Client. Listing 1 is a typical SOAP request message, and Listing 2 is a typical SOAP response message.
Soap-env: body>
Soap-env: envelope>
SOAP Server
SOAP Server is also a SOAP perceived machine that accepts requests from SOAP Client and create appropriate responses. The encrypted response will be sent to the SOAP Client that issues a request. There are three entities inside SOAP Server:
1. Service Manager
2. Deployed Service List
3. XML Translator
Service Manager manages the service response request. In the SOAP request in Listing 1, the node
m: getListofmodelsResponse>
Soap-env: body>
Soap-env: envelope>
Actual Service
In the frame, the frame is ahead of the Actual Service displayed the location of the Actual SRRVICE. The implementation of the service may be a COM component or a JavaBean component. XML Translator will convert an XML structure into a suitable method call. When XML Translator calls an Actual SRRVICE method, these methods perform their function and return results to XML Translator.
The two ends of the arrows connected to the XML Translator and the Actual Service in Figure 1 are in a business, which means that the same organization controls the interfaces at both ends of the communication. In contrast, SOAP Client and SOAP Service cross the boundaries of the company. This is the use of SOAP.
SOAP request response mechanism
SOAP Client Transports SOAP messages to SOAP Service Use HTTP protocol transfer. This is called SOAP binding http. When SOAP Service receives a message, he passes the message to the Service Maneger. SOAP Service Checks the service of the SOAP message request in the Deployed Service List. If there is no service, he sent back to the SOAP Client if the response request failed. However, if there is a service, it is a suitable language conversion by XML Translator to access the implementation of Actual Service. The implementation of the service will handle the request and return the result to the XML Translator. XML Translator will convert the result to the SOAP response of the SOAP Client. Similarly, HTTP binding is also used on the transmission of SOAP response. SOAP binds HTTP
When you give HTTP to the SOAP to bind or operate SOAP on HTTP, you can actually add an HTTP header on the SOAP request and response. Listing 1 is a typical SOAP request, while Listing 3, 4, 5, and 6 demonstrates the SOAP request to add HTTP heads on Listing 1. Similarly, Listing 7 demonstrates the SOAP response to the HTTP header on Listing 2.
When you use SOAP on HTTP, the Content-Type field must be Text / HTML. You can see the details of Listing 3 in Listing 7.
A SOAP request using HTTP
You can combine SOAP on the request method of HTTP POST. To send a SOAP HTTP request, you must provide a soapaction field on the HTTP header.
SOAPAction defines the purpose of the SOAP request. The server (such as filtering the firewall for the SOAP request message on HTTP) can use the value of the soapaction to make a decision.
The HTTP client must use the field of the HTTP header when emitting the SOAP request. The value of the soapaction can be taken below:
SOAPACTION: "Uri-Reference"
SOAPACTION: "FileName"
SOAPACTION: ""
SOAPACTION
Post / vendors http / 1.1
Host: www.mobilephoneservice.com
Content-Type: "text / xml"; charset = "UTF-8"
Content-Length: nnnn
SOAPACTION: "www.mobilephoneservice.com/vendors/mobilephoneservice#getlistofmodels"
XML Version = "1.0"?>
m: getListofmodels>
Soap-env: body>
Soap-env: envelope>
Figure Listing 3 contains the following URI reference in the SOAPACTION
Www.mobilephoneservice.com/vendors/mobilephoneservice#getlistofmodels
This soapaction explains two things: First, the detailed address of SOAP is www.mobilephonePhoneService, the second is the name of the method we are interested in (#getlistofmodels) .POST / VENDORS HTTP / 1.1
Host: www.mobilephoneservice.com
Content-Type: "text / xml"; charset = "UTF-8"
Content-Length: nnnn
SOAPACTION: "MobilePhoneService # getListofmodels"
XML Version = "1.0"?>
m: getListofmodels>
Soap-env: body>
Soap-env: envelope>
Figure Listing 4 contains a file name (MobilephoneService # getListofmodels) in the SOAPACTION. The MobilePhoneService file must be placed under the host URI (WWW. Mobilephone.com/vendors). The host URI is composed of a Host field plus folder name (/ vendors) by the HTTP header.
Post / vendors http / 1.1
Host: www.mobilephoneservice.com
Content-Type: "text / xml"; charset = "UTF-8"
Content-Length: nnnn
SOAPACTION: ""
XML Version = "1.0"?>
m: getListofmodels>
Soap-env: body>
Soap-env: envelope>
Figure Listing 5's SOAPACTION contains a control string (""). Empty string illustrates the target of SOAP with the same host URI (WWW. Mobilephone.com/vendors).
Post / vendors http / 1.1
Host: www.mobilephoneservice.com
Content-Type: "text / xml"; charset = "UTF-8"
Content-Length: nnnn
SOAPACTION:
XML Version = "1.0"?>
m: getListofmodels>
Soap-env: body>
Soap-env: envelope>
Figure Listing 6 has no value. This indicates the information of the goal without messages.
Use HTTP SOAP response
There are two types of SOAP response:
● Successful SOAP operation generated SOAP results.
● SOAP error messages generated by unsuccessful SOAP operations.
HTTP / 1.1 Content-Type: "text / xml"; charSet = "UTF-8"
Content-Length: nnnn
m: getListofmodels>
Soap-env: body>
Figure Listing 7 is a meaningful result from the SOAP service returns.
Figure Listing 8 is a typical SOAP error message. Soap HTTP responded to the semantics of the HTTP status code of communication status information in HTTP. When the processing request fails, the SOAP HTTP server must issue a response to the HTTP 500 internal service error of the SOAP message with the SOAP error element.
HTTP / 1.1 500 INTERNAL Server Error
Content-Type: "text / xml"; charset = "UTF-8"
Content-Length: nnnn
Soap-env: fault>
Soap-env: body>
Soap-env: envelope>
SOAP and E-MAIL
HTTP is not the only solution for binding the SOAP message. You can use other mechanisms to use other mechanisms for SOAP binding in HTTP steps. Bind SOAP to SMTP, you can create a one-way channel. Two one-way messages can establish request / response communication. In order to send SOAP messages using SMTP, you must follow the steps below:
● Use the mime-version field of the SMTP header
MIME-VERSION field Use the version number to distinguish between different versions of MIME (Multi-purpose Internet mail expansion protocol). He allows the mail service agent (such as a POP service) to distinguish between new and old version MIME generated mail messages. Figure Listing 9 is the MIME-VERSION field of the SMTP header.
TO:
Reply-to:
Date: Sat, 2 Feb 2002 16:00:00
Message-id: <4fab345c8d93e93b7a6e9@punjab.com>
MIME-VERSION: 1.0
Content-type: text / xml; charSet = UTF-8
Content-Transfer-Encoding: Quoted-Printable
XML Version = "1.0" encoding = "UTF-8"?>
prNT: echostring>
Soap-env: body>
Soap-env: envelope>
● Use the Content-Type field of the SMTP header
The Content-Type field is used to indicate the data type of the message body weight. "Text / XML" is a value that can be removed. Figure Listing 9 uses the Content-Type field.
● Use the Content-Transfer-Encoding field of the SMTP header
The Content-Transfer-Encoding field is used to illustrate the type of transfer encoding, that is, what kind of data you want to transmit is a character format or a binary format. Figure Listing 9 uses the quoted-printable encoding is the printed character in the ASCII character set. It is data encoded by mail out the agent unlikely to modify the results bytes.
SOAP mode and its writing
SOAP message
The SOAP message is an XML document, which must have a SOAP envelope that contains optional SOAP headers and required SOAP.
Elements of SOAP mode:
● Envelope
● HEADER
● Body
● Faule
Envelope:
Envelope is the root node for SOAP messages. This node must appear in the SOAP message. ENVELOPE uses SOAP namespace ID: http: //schemas.xmlsoap.org/soap/Envelope/ is required. If the Envelope node contains an error namespace, an ENVELOPE namespace version is generated. Listing 10 is an empty envelope node. You call it empty letter to emphasize that the envelope node must contain a "letter" before "POST". The letter in SOAP mode is a SOAP body and HTTP POST is a transmission mechanism.
Listing 10
Soap-env: envelope>
HEADER
The SOAP head is optional. You can skip the SOAP header to encapsulate a SOAP body in SOAP Envelope. The SOAP header provides a mechanism for expanding the SOAP message function. For example, adding verification in a SOAP head is a typical extension. In this example, there is a verification frame that will be transmitted under the underlying. You can see the implementation of HEADER in SOAP in Listing 11.
Listing 11
m: ORDER>
Soap-env: header>
Soap-env: envelope>
Body
The Body node will contain the message you want to send. This is a necessary node, and its word point is usually belonging to a user-defined namespace. Listing 12 shows a SOAP message with a user-defined namespace "U". The Body node is used to include the required information. The Body node is required for SOAP messages, and it must be the direct child node of the SOAP ENVELOP node. He must follow directly behind the SOAP Header. If there is no HEADER node, follow it directly behind the Envelop node. Body can contain a word node, and the byage point can have its namespace.
m: ORDER>
Soap-env: header>
u: getprice>
Soap-env: body>
Soap-env: envelope>
Fault
This node indicates an error message. It must appear at a fody once. Typically, the fault node appears in the SOAP response indicates that the SOAP request is wrong.
Fault's child node:
● Faultcode (fault logo)
● Faultstring (Fault Description)
● Faultactor (why to trigger errors)
● Detail (error details. Usually the error details for the application of the namespace of the namespace of the corresponding SOAP request.)
Listing 13 is a typical Fault message.
Listing 13
m: ORDER>
Soap-env: header>
Application IS Not Responding Properly.
msg>
d: faultdetail>
detail>
Soap-env: fault>
Soap-env: body>
Soap-env: envelope>
SOAP request for the first part of the WSDL file
After the syntax of the SOAP message, I will demonstrate how to develop a SOAP request for MobilePhoneService for the first part of this series. In the first part, you have designed a complete WDL interface for MobilephonService. Mobile phone company offers two ways: one is getListofmodels and the other is getprice (modelnumber). GetListofModels does not have a parameters, return to the mobile phone model list and getprice (modelnumber) has a parameter modelNumber, returns the price of the request model. You need to put them into the format of the SOAP request, before this, I want to show the general format of the SOAP request and the response.
Instance: "Method Name"> Soap_envelop: body> Soap-env: envelope> A SOAP request or response can only define a method of service. The general form of the SOAP request is shown in Listing 14. Listing 16 is an actual request to call the getListofmodels method. In Listing 16, I provide the name and URI of the method. Because GetListofmodels do not have parameters, Listing 15 XMLns: instance = "uri where method is located"> returnide> Instance: "Method Name" "Response"> Soap-env: body> Soap-env: envelope> Listing 15 is a general SOAP response. The APACH SOAP server adds the response keyword after the method name and encapsulates the return value in the XML Version = "1.0" encoding = "UTF-8"?> WSDL-based services on the SOAP server In this section we will post the WSDL service in the first part to an Apache SOAP server. The Apache SOAP toolkit holds WSDL service information in a published description file. The release description file contains the name of the WSDL service and its method. The release description file is provided to the SOAP server at runtime. The release description file also contains the address of the JavaBean component that implements the interface. Listing 20 ID = "URN: Service-Urn"> Scope = "request" Methods = "Exposed-Methods"> isd: provider> ISD: FAULTLISTENER> ISD: Service> Listing 20 is a skeleton that publishes a description file, and the WSDL service is published in the WSDL service requires three information (URN: Service-Urn, Exposed-Metho and Implement-Class). URN: Service-URN is the name of the published service. The method list of the Exposed-Metho service. In this release, GetListofmodels and getPrice are released. The Implement-Class is a Java class with full name. Such as Samples.PhoneQuote.MobilePhoneService. In this trial, you have the following path structure: Apache SOAP Server: C: / Foo / SOAP-2-2 Mobile Pone Service implementation C: / foo / soap-2-2 / samples / phonequotes / mobilephoneservice Therefore, the class path is related to the directory when installing the SOAP toolkit. I didn't provide the actual Java implementation class. This requires something on business logic or other things. ID = "URN: MobilePhoneService"> Scope = "request" Methods = "getListofmodels getprice"> isd: provider> Org.apache.soap.server.domfaultlistener ISD: FAULTLISTENER> ISD: Service> Listing 21 is a complete description of the WSDL file in the first part. Communication with SOAP client with SOAP server I have prepared an example to demonstrate the communication of the SOAP client with the SOAP server. So I gave three lists: Startup.html (Listing 22), Operation.html (Listing 23) and Excute.jsp (Listing 24). Startup.html is a simple HTML file. It is a user interface that determines which SOAP method called by the user. Listing 22 SOAP METHOD Invocation Demo b> font> p>
Click Any of The Method Name to Execute. 1. Get The List of All Models That We Manufacture .... getListofmodels font> 2. Get the price of any particular model .................... . getprice font> b> Body> Html> Operation.html (Listing 23) Let the user enter the parameter of the call method. Listing 23 GetPrice Operation Input Form b> font> p>