Using WSDL Releases WebService (Part 2) Simple Object Access Protocol - Learn SOAP Syntax and WSDL to WSDL using SOAP

xiaoxiao2021-03-06  23

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 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 contains the name of the service. Service Manager reads the service client to the name of the service you want to call and to Query if you have this service in the Deployed Service List in which all service lists containing the SOAP Service. If there is Service Manager, send the SOAP request to XML Translator. XML Translator converts the XML structure of the SOAP to programmers to implement the actual service. XML Translator also returns the response returned by the Actual Service back to the SOAP response of the XML structure. Listing 2 is an example of a SOAP response.

m1

m2

m3

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"

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"

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: ""

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:

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

m1

m2

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

Failed to Process The Request

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: from:

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

PUT Your Mail Message

● 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

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

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.

m1

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

SOAP-ENV: Server

Not Necessary Information>

Application IS Not Responding Properly.

12

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.

Value

value

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, is an empty node.

Listing 15

XMLns: instance = "uri where method is located">

Value

Value

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 node as the direct child node of the method node. If the return value is a complex type, then the node will contain one or more nodes. Compared to Listing 15, Listing 17 is the actual response of method GetListofmodels. The return value in Listing 17 is the Vector type, so the nodes. Similar to this is the Listing 18 and Listing 19, which shows the SOAP requests and responses of the MobilePhoneService's getPrice () method.

XMLns: XSI = "http://www.w3.org/1999/xmlschema-instance" XMLns: XSD = "http://www.w3.org/1999/xmlschema"> m1 m2 m3 m4 m5

xmlns: xsi = "http://www.w3.org/1999/xmlschema-instance" XMLns: xsd = "http://www.w3.org/1999/xmlschema"> m1 < SOAP-ENV: ENVELOPE XMLNS: SOAP-ENV = "http://schemas.xmlsoap.org/soap/envelope/" XMLns: XSI = "http://www.w3.org/1999/xmlschema-instance" XMLns: XSD = "http://www.w3.org/1999/xmlschema"> 5000

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">

Org.apache.soap.server.domfaultlistener

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">

Org.apache.soap.server.domfaultlistener

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


Click Any of The Method Name to Execute.

1. Get The List of All Models That We Manufacture ....

getListofmodels 2. Get the price of any particular model .................... .

getprice

Operation.html (Listing 23) Let the user enter the parameter of the call method.

Listing 23


GetPrice Operation Input Form


description:

Method getprice is buy to get price of given model number

parameter (s)

Model Number

(Required)

Excute.jsp (Listing 24) is the focus. It detects the method of calling and its parameters, then sending a method to the remote server to call the request.

Listing 24

<% @ page language = "java" import = "java.util.vector"%>

<% @ page import = "java.net.malformedurlexception, java.net.URL"%>

<% @ page import = "java.util.vector"%>

<% @ page import = "org.apache.soap.soapexception,

Org.apache.soap.Constants "%>

<% @ page import = "org.apache.soap.rpc.call, org.apache.soap.rpc.response,

Org.apache.soap.rpc.parameter "%>

<% @ page import = "org.apache.soap.transport.http.soaphttpConnection"%>

<% @ page import = "org.apache.soap.fault"%>


<%

Boolean ISPARETER = FALSE;

SOAPHTTPCONNECTION SOAPTRANSPORT = New soapHttpConnection ();

// Address of The Remote Server.

// Normally this stay be dynamically passed and detected.

// We Have Hard Coded It Only for DemonStration.

URL URL = New URL ("http: // localhost: 8080 / soap / servlet / rpcrouter);

// build the call.

Call call = new call ();

Call.SetTargetObjecturi ("URN: MobilePhoneService);

Call.SetsoAptransport (SOAPTRANSPORT);

Call.setencodingstyleuri (constants.ns_uri_soap_enc);

// We'll Detect Which Method User SELECTED

// and give a call accountingly.

// We'll Pass Parameters if present.

IF (Request.getParameter ("parameter")! = null)

ISPARETER = TRUE;

IF (Request.GetParameter ("index"). Equals ("0")) {

Call.setMethodName ("getprice");

Vector params = new vector ();

String message = new string (Request.getParameter ("parameter));

Params.AddeElement (New Parameter ("Message", String.class,

Message, NULL);

Call.SetParams (params);

}

Else

Call.SetMethodName ("getListofmodels");

Response resp = call.invoke (url, / * actionuri * / ");

Out.println ("

Response of [" Call.getMethodName () "]


");

// Check The Response.

IF (resp.generatedfault ()) {

Fault fault = resp.getfault ();

Out.println (" fault is: " Fault.GetFaultcode ()

"[" Fault.GetFaultString () "]");

} else {

Parameter Result = Resp.getReturnValue ();

Out.println (" Response IS: " Result.getValue () "");

}

%>

Run this program you need two Apache SOAP servers. A interaction for users with the host. Another (also known as remote server) is used to publish WSDL-based services in the first part. The remote server address (http: // localhost: 8080 / soap / servlet / rpcouter) is only used for demo in Execute.jsp. In fact, you will read the remote server address from the WSDL file.

Simple data type and combined data type in SOAP

The difference between the simple data type and the combined data type is described below. I will show how to package them in SOAP.

Simple data types include String, Float, Integer, Enumeration, and more. If the name of the mobile phone is the String type. The combined data type is a combination of simple data types. If the student type may have multiple properties: String type name, INT type number.

Listing 25 contains complex data type Mobile. You can use this type in your SOAP request. Listing 25

1

2

3 xmlns: xsd = "http://www.w3.org/1999/xmlschema"> 4 targetnamespace = "www.mobilephone ".com/phonequote">

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

The fifth line of Listing 25 is the name of the type and the sixth line shows this is a complex data type. The complex data type has properties, and seven to 12 lines are the properties of data type Mobile. Chain VII indicates that the mobile type has a name named modelNumber type Int. Similar to nine, ten lines are the properties of the same type of different names. The eighth row is the attribute named the ModelName type String.

Eleven rows is complicated because it contains a child node of SimpleType. We define a simple type in the Mobile type. This simple type name is ModelColor is an EnumAration type. He has a value XSD: string base property, which shows that the simple type ModelColor base type is Sting. Enumeration Type Description We can select a value as an attribute.

Use a combination type in the SOAP request

Listing 26 demonstrates the use of a combined type in the SOAP request. The ADDMODEL method of the M namespace is called in the envelope body. Listing 26 uses the Mobile data type defined in Listing 25.

The AddModel method has a parameter of a Mobile type. We used the MSD namespace before Mobile. Listiing 26's node declares that the namespace. This is an example of using user-defined type data in the SOAP request.

1

3 xmlns: msd = "www.mobilephone ".com/phonequote">

4

5

6

7 1

8 mlr97

9 10

10 4

11 White

12

13

14

15

to sum up

Now we have learned SOAP grammar, request, response, HTTP binding, and use E-mail in SOAP. You also see how the SOAP server responds to the SOAP client. Finally, I briefly tell the user to customize type data. Custom Type Data is a high-level topic that requires subsystems. In this series, we will discuss this topic in more detail. And I also checked the interaction capabilities of SOAP (that is, how SOAP is executed in different sellers).

Original link: http://www-128.ibm.com/developerWorks/webservices/library/ws-intwsdl2/index.html

转载请注明原文地址:https://www.9cbs.com/read-40036.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.039, SQL: 9