Simple Object Access Protocol (SOAP) Primary Guide

xiaoxiao2021-03-06  114

The SOAP (Simple Object Access Protocal) technology helps implement a large number of heterogeneous procedures and platform interoperability, making the existing applications accessible by users. SOAP is a combination of mature HTTP-based Web technology with XML flexibility and scalability.

This article takes you a comprehensive review of the process of remote process call (ORPC) technology to help you understand the basis of SOAP technology, and it overcome many of the defects of the presence techniques such as CORBA and DCOM. Subsequently tell the detailed SOAP coding rule and put the focus on how the SOAP is mapped to the existing ORPC concept.

introduction:

When I started calculating calculation as my profession in 1984, most of the programmers did not care about the network protocol. But in the 1990s Network has become ubiquitous, now if anyone using a computer, it is difficult to imagine it. Today, the general programmers show greater interest in establishing scalable distributed applications, rather than simply focusing on using MFC to achieve individual floating translucent non-rectangular Coolbars.

Programmers usually like to think about problems with programming models, and rarely consider the network protocol. Although this is usually very good, but in this article, I will discuss SOAP is a network protocol without obvious programming model. This does not mean that the architecture of SOAP will fundamentally change your programming. Instead, a major objective of SOAP is to make the existing application can be used by a broader user. In order to achieve this, there is no SOAP API or SOAP object request agent (SOAP ORB), and SOAP is assumed that you will use as many technologies as possible. Several major CORBA vendors have committed to support the SOAP protocol in their ORB products. Microsoft also promises to support SOAP in future COM versions.

Developmentor has developed a reference implementation, which allows any Java or Perl programmers on any platform to use SOAP.

The guidelines behind SOAP are "it is the first technology without inventions". SOAP uses two protocols that have been widely used: HTTP and XML. HTTP is used to implement SOAP RPC style transmission, and XML is its encoding mode. The HTTP server (such as an IIS or Apache) of the HTTP server (such as MS or Apache) immediately became the ORBS of SOAP. Because more than half of the web server uses IIS or Apache, SOAP will benefit from the extensive and reliable use of these two products. This does not mean that all SOAP requests must be routed through the web server, and the traditional web server is just a way to assign SOAP requests. Therefore, Web services such as IIS or Apache is sufficient to establish SOAP enabled applications, but it will never be necessary.

As this article will be described, SOAP simply encodes HTTP's transfer content. The most common application of SOAP is an RPC protocol. In order to understand how SOAP work, it is necessary to briefly review the history of the RPC protocol.

RPCS history

Two major communication models for establishing a distributed application are messaging (often combined with queues) and request / responses. The message delivery system allows the communication to send a message at any time. The request / response protocol limits the communication mode to both parties of the request / response. Messaging-based applications strongly realize that they are communicating with external parallel processes and require an explicit design style. Applications based on request / response are more like a single process, because the application of the request is more or less blocked until the response from another process is received. This makes the request / response communication naturally suitable for the RPC application.

Although the message communications and request / response each have their advantages, they can be implemented with each other. The message system can be created with a lower request / response protocol. DCE RPC is used to establish most of the control logic in the internal MSSAGE Queue Server (MSMQ) of Microsoft. The RPC system can also be established by the lower-level messaging system. The associated ID provided by MSMQ is for this purpose. Regardless of the evaluation, most applications still tend to use the RPC protocol because they are widely used, and their simpler design, and more natural maps of programming technology. In the 1980s, two major RPC protocols were Sun RPC and DCE RPC. The most popular Sun RPC application is the NetWork File System (NFS) used by most UNIX systems. The most popular DCE RPC application is Windows NT? And it uses the DCE RPC protocol to implement many system services. These two protocols have been proven to apply to a wide range of applications. However, in the end of the 1980s, the popularity of object-oriented technology is addicted to the software industry to establish a link between object-oriented languages ​​and RPC-based communications.

The Object RPC (ORPC) protocol generated in the 1990s is trying to link the object-oriented and network protocol. The main difference between the ORPC and RPC protocols is ORPC code to mapping from communication terminals to a language level object. There is a cookie in the header of each ORPC request, and the server's program can be used to locate the target object in the server process. Usually this cookie is just an index of an array, but other technologies are often used, such as using symbolic names as the HASH table.

Figure 1 ORPC request and response

Figure 1 shows a typical ORPC request and response. There are several request header components to be used by the server-side handler for distribution calls. The object endpoint ID is used to locate the target object in the server process. The interface identifier and method identifier are used to determine which method in the target object is called. The transmission body is used to transfer the value of the [IN] and [IN, OUT] parameters in the request ([OUT] and [IN, OUT] in the response). It should be noted that the optional protocol extension can appear between the header file and the transfer body. This is a practice in protocol design because it allows new services to be mounted on ORPC requests and services. Most ORPC systems communicate additional context information (such as transaction information and causality identifiers) in this area.

At present, two major OPRC protocols are DCOM and CORBA Internet Inter-ORB Protocol (IIOP) or more General Inter-ORB Protocol (Giop). The request format of DCOM and IIOP / Giop is very similar. Both protocols use an object endpoint ID to determine the target object, which method is determined by the method identifier.

These two protocols have two main points: the main point is the use of IIOP / Giop, the interface identifier is implied, because a given CORBA object only implements an interface (although omg is currently in progress each object Standardization work supporting multiple interfaces). Another fine difference of the DCOM and IIOP / Giop request is the format of the parameter value in the transport body. In DCOM, the transmission of network data expression (NDR) is written, and in IIOP / Giop, the transport volume is written in the format of public data expression (CDR). NDR and CDR processes different data expressions on various platforms, respectively. But there are some small differences between these two formats, which make them incompatible with each other.

Another important difference between the ORPC and the RPC protocol is the naming method of the communication endpoint. In the ORPC protocol, some of the deliverable expressions for ORPC endpoints are required to pass object references between the network. In CORBA / IIOP, this expression is called an interactive object reference (IOR). IORS contains addressing information expressed in compact format, using it any CORBA product can determine an object endpoint. In DCOM, this expression is referred to as OBJREF, which combines distributed reference computing and endpoint / object identity. Both Corba and DCO provide a high-level mechanism for searching object endpoints on the web, but eventually these mechanisms are mapped back to IRS or Objrefs. 3 is a representation of how an IOR / OBJREF is associated with addressing information in the IIOP / DCOM request message. What is the current technology?

Although DCOM and IIOP are fixed protocols, the industry has not fully turned to any of these protocols. Part of the reason that is not integrated is the problem of culture. And when some organizations attempt to standardize one or another agreement, the technical applicability of the two protocols is questioned. Traditionally, DCOM and CORBA are considered a communication protocol for reasonable servers to the server. However, both the communication between the client to the server is a significant weakness, especially when the client is spread on the Internet.

DCOM and CORBA / IIOP are used to use protocols on a single vendor solution. Although two protocols are implemented on various platforms and products, the reality is the selected release requires the implementation of a single manufacturer. In the case of DCOM, this means that each machine is to run in Windows NT. (Although DCOM has been transferred to other platforms, it only has a wide extension on Windows?). In CORBA case, this means that each machine is to run the same ORB product. It is possible to make two CORBA products to call each other, but many advanced services (such as security and transactions) are usually not interactive. Moreover, any other manufacturer is difficult to optimize the optimization of the same machine, unless all applications are built on the same ORB product.

DCOM and CORBA / IIOP are dependent on carefully managed environments. Two arbitrary computers make DCOM or IIOP's chances of successful calls (Calls out of the box) in the environment. Especially when considering safety, this is especially true. Although writing a tightening package that can successfully use DCOM or IIOP (Shrink-Wrap) applications, this is more focused more than Socket-based applications. This is especially applicable for tedious but necessary configurations and installation management tasks.

DCOM and CORBA / IIOP are dependent on quite high-tech operating environment. Although COM in the process seems to be particularly simple, the COM / DCOM remote handler is absolutely not just a few days. IIOP is a protocol that is easier than DCOM, but two protocols have considerable deep rules to process data arrangements, type information, and bit operations. This makes the general programmers to construct a simple CORBA or DCOM call in the case where the OLB product or OLE32.DLL is not comparable.

Perhaps the most unbearable point for DCOM and CORBA / IIOP is that they cannot play a role on the Internet. For DCOM, the general user's IMAC or inexpensive running Windows 95 PC compatible machine should use your server to perform domain authentication is almost impossible. Worse, if the firewall or proxy server separates the machine and server machine, any possibility of any IIOP or DCOM package is very low, mainly because most Internet connection technology is caused by the preference of the HTTP protocol . Although some vendors such as Microsoft, Iona and Visigenic have established channel technology, these products are easily sensitive to configuration errors and they are not interactive.

These problems in a server community cannot affect the use of DCOM or IIOP. Because the number of hosts in the server community is very small (generally hundreds of thousands, rather than thousands), this offsets the cost of DCOM-based lifecycle management. In the server group, all hosts are managed by a public administrative domain, making unified configurations possible. Relatively small amounts of machines can also maintain the cost of commercial ORB products to control because there is only a small amount of ORB permission. If only IIOP is used in the server community, only a small amount of ORB permissions are required. Finally, all hosts have direct IP connections in the server community, which eliminates DCOM and IIOP issues related to the firewall. HTTP as a better RPC

Using DCOM and CORBA in server communities are common practice, but clients use HTTP to enter the server community. HTTP and RPC agreements are very similar, it is simple, extensive, and more easy to play against firewalls than other protocols. HTTP requests are generally processed by web server software (such as IIS and Apache), but more and more application server products are supporting HTTP as another protocol except DCOM and IIOP.

Like the DCOM and IIOP, the HTTP layer requests / responds to communications over TCP / IP. An HTTP client is connected to the HTTP server with TCP. The standard port number used in HTTP is 80, but any other port can also be used. After establishing a TCP connection, the client can send a request message to the server side. The server sent back an HTTP response message to the client after processing the request. The request and response message can contain information of any transport body, usually marked with the Content-Length and Content-Type HTTP headers. Below is a legal HTTP request message:

Post / foobar http / 1.1

Host: 209.110.197.12

Content-Type: Text / Plain

Content-Length: 12

Hello, World

You may have noticed that the HTTP header is just general text. This makes it easier to diagnose HTTP issues with a package inspection program or text-based Internet tool (such as telnet). HTTP's text-based properties also make HTTP more easily applicable to popular low-tech programming environments in Web development.

The first line of the HTTP request contains three components: HTTP method, request -uri, protocol version. In the previous example, these respectively correspond to POST, / FOOBAR, and HTTP / 1.1, respectively. The Internet Engineering Task Group (IETF) has been standardized with a fixed HTTP method. GET is HTTP to access the web. POST is the most commonly used HTTP method for establishing applications. Unlike Get, POST allows any data to be sent from the client to the server side. Request URI (Uniform Resource Identifier) ​​is an HTTP server-side software that is used to identify a simple identifier for the request's target (it is more like a IIOP / Giop Object_key or a DCOM IPID). For more information about URIS, please refer to "Uris, URLS, AND URNS". The version of the agreement in this example is http / 1.1, which indicates the rules of the RFC 2616. HTTP / 1.1 adds several features than HTTP / 1.0, including support for large block data transmission, and support for maintaining TCP connections between several HTTP requests.

The third row of requests, the fourth line, specifies the size and type of the requested body. The content-length header specifies the number of bits of the body information. The Content-Type type identifier specifies the syntax of the MIME type as the body information. HTTP (like DCE) Allows the server and client to negotiate the transfer syntax for the preparation of information. Most DCE applications use NDR.. Most web applications use text / html or other text-based syntax.

Note the space between the Content-Length head and the requested body in the above example. Different HTTP heads are defined by the Carriage-Return / line code sequence. These heads and bodies are used to delineate the boundaries with additional carrier-return / row code sequences. The request then includes the original byte, the syntax and length of these bytes, is identified by Content-Length and Content-Type HTTP headers. In this example, the content is the 12-byte common text string "Hello, World". After processing the request, the HTTP server is expected to send back an HTTP response to the client. The response must include a status code to represent the result of the request. The response can also contain any physical information. Here is an HTTP response message:

200 OK

Content-Type: Text / Plain

Content-Length: 12

DLROW, OLLEH

In this example, the server returns state code 200, which is the standard success code in HTTP. If the server side cannot crack the request code, it will return the following response:

400 Bad Request

Content-Length: 0

If the HTTP server determines that the request to the target URI should temporarily turn to another different URI, the following response will be returned:

307 Temporarily Moved

Location: http://209.110.197.44/foobar

Content-Length: 0

This response tells the customer that the request will be able to be satisfied by re-delivering it to the address specified in the location header.

All standard status codes and heads are described in RFC 2616. There are very few contents directly related to SOAP users, but there is an obvious exception. At HTTP / 1.1, the underlying TCP connection is reused between multiple request / response. The HTTP Connection header allows the client or any party in the server to close the underlying connection. By adding the following HTTP heads to requests or responses, both parties require to turn off their TCP connections after processing requests:

Connection: Close

When interacting with the HTTP / 1.0 software, in order to maintain the TCP connection, it is recommended to add the following HTTP head to each request or response:

Connection: Keep-alive

This head makes the default HTTP / 1.0 protocol restarted the behavior of the TCP connection after each response.

One advantage of HTTP is that it is being widely used and accepted. Figure 4 shows a simple Java program that transmits the requesting request and parses the result string from the response.

The following is a simple C program with CGI to read strings from HTTP requests and returns its reverse skewers via HTTP response.

#include

INT main (int Argc, char ** argv) {

Char buf [4096];

INT CB = Read (0, BUF, SIZEOF (BUF));

BUF [CB] = 0;

Strrev (BUF);

Printf ("200 OK / R / N"); P>

Printf ("Content-Type: Text / PLAIN / R / N");

Printf ("Content-Length:% D / R / N", CB);

Printf ("/ r / n");

Printf (BUF);

Return 0;

Figure 5 shows a more popular version, the server's implementation is to use Java Servlet to avoid overhead of each request of CGI.

In general, CGI is a method of spending a minimum write HTTP server-side code. In fact, each HTTP server-side product provides a more efficient mechanism to allow your code to process an HTTP request. IIS provides ASP and ISAPI as a mechanism for writing HTTP code. Apache allows you to write modules with C or Perl running in the Apache background program. Most application server software allows you to write Java Servlet, COM components, EJB Session Beans, or CORBA Servants based on the portable object adapter (POA) interface. XML as a better network data expression (NDR)

HTTP is a quite useful RPC protocol, which provides support for most of the IIOP or DCOM in group frame, connection management, and serialized object applications. (And URLS and IRS and Objrefs are amazingly close to). HTTP is missing is the parameters in the RPC call in a single standard format. This is the land of XML.

Like NDR and CDR, XML is a neutral data expression protocol that is unrelated to the platform. XML allows data to be serialized into a form that can be delivered so that it is easily decoded on any platform. XML has the following features of NDR and CDR:

A large number of XML encodings and decoding software exists on each programming environment and platform

XML based on text, fairly easy to use low-tech programming environment

XML is a particularly flexible format, which is easy to expand in a consistent way.

To support scalability, each element and attribute in XML have a named domain URI associated with it, this URI is specified with an XMLNS property.

Consider the following XML documentation:

Hello, World

This is a comment !!

The names of the elements and are URN: Schemas-develop-com: StringProcs. The names of the is http://foo.com/documentation. The second URI is also a fact that a URL is not important. In both cases, the URI is simply used to eliminate the elements , , and any other elements that happen to have the same marking name.

For convenience, XML allows the name domain URIS to be mapped into local unique prefixes. This means that the following XML documents are in semantically equivalent to the above document:

XMLns: sp = "URN: Schemas-develop-com: StringProcs"

XMLns: DOC = 'http://foo.com/documentation'

>

Hello, World

This is a comment !!

The following form is easier to use, especially if there are many domain uris.

XML also supports tape type of data. The XML Schema Specification is being launched to describe a word collection for describing the XML data type. Here is a description of an element XML Schema:

XMLns = 'http://www.w3.org/1999/xmlschema'

Targetnamespace = 'URN: Schemas-develop-com: stringprocs'

>

This XML Schema definition describes the XML name domain URN: Schemas-develop-com: StringProcs contains an element called , which contains a child element called String1 (type string), which is 0 Allow more than the specified element.

The XML Schema specification also defines a set of built-in raw data types and a mechanism for the type of elements in an XML document. The following XML document uses the XML Schema type properties to link the elements and type names:

XMLns = 'http://customer.is.king.com'

XMLns: xsd = 'http://www.w3.org/1999/xmlschema'

>

DON BOX

23.5

Connecting an XML document instance to new mechanisms described by XML Schema are being standardized during writing.

HTTP XML = SOAP

SOAP uses XML's use code to request and respond to parameter encoding mode and use HTTP to transfer. This seems to be a bit abstraction. Specifically, a SOAP method can simply see HTTP requests and responses that follow the SOAP coding rules. A SOAP terminal can be considered as an HTTP-based URL that is used to identify the target call. Like CORBA / IIOP, SOAP does not require specific objects to be bound to a given terminal, but by specific implementation programs to determine how the object terminal identifies the object to the server side.

SOAP request is an HTTP POST request. The Content-Type requested by the SOAP request must use text / XML. And it must contain a request -uri. How does the server explain that request -uri is related to implementation, but many implementations may be mapped to a class or an object. A SOAP request must also use the SOAPMETHODNAME HTTP header to indicate the method that will be called. Simply put, the SOAPMETHODNAME header is a method name associated with the application of the URI specified range, which is divided into the URI with a # 符 as a separator:

SOAPMETHODNAME: URN: STRINGS-COM: istring # Reverse

This header indicates that the method name is Reverse, the range URI is URN: Strings-Com: istring. In SOAP, the name domain URI specified by the method name range is functionally equivalent to the interface ID of the method name range in DCOM or IIOP.

Simply put, a SOAP request HTTP body is an XML document that contains the value of [IN] and [IN, OUT] parameters in the method. These values ​​are encoded into a sub-element of a significant call element, which has the method name and name domain URI of the SOAPMETHODNAME HTTP header. The calling element must appear in a standard SOAP and element (these two elements will be discussed later). Here is the simplest SOAP method request: post / string_server / Object17 http / 1.1

Host: 209.110.197.2

Content-Type: Text / XML

Content-Length: 152

SOAPMETHODNAME: URN: STRINGS-COM: istring # Reverse

Hello, World

The SOAPMETHODNAME header must match the first child element under , otherwise the call will be rejected. This allows the firewall administrator to effectively filter the call to a specific method without resolving XML.

The format of the SOAP response is similar to the request format. In response to the [OUT] and [IN, OUT] parameters of the method, this method is encoded as a sub-elements of a significant response element. The name of this element is the same as the name of the requested call element, but is connected in a response suffix. Below is a SOAP response to the front SOAP request:

200 OK

Content-Type: Text / XML

Content-Length: 162

DLROW, OLLEH

Here the response element is named ReverseResPonse, which is the method name to follow the response suffix. It is important to note that there is no soapmethodname http header. This head is only required in the request message, and does not need in the response message.

Figures 6 and 7 indicate how SOAP corresponds to each other with the ORPC protocol previously discussed. Let Many SOAP novices confused that there is no request to use the request header for the SOAP server to distribute the request; this is left as an implementation details. Some SOAP servers will map the mais to the class name, and assign an instance of the call to a static method or a class that survive within the request. Other SOAP servers will request -uris to map to always survived, often using query strings to encode a keyword used to locate in server processes. There are also other SOAP servers to encode an object key with HTTP cookies, which can be used to recover the status of the object in each method request. It is important that customers don't know these differences. Customer software simply follows HTTP and XML rules to form SOAP requests, allowing server freedom to request services in its way that it is considered to be.

Core of SOAP

The XML characteristic of SOAP is to serialize an instance of the data type into XML encoding mode. In order to achieve this, SOAP does not require the use of traditional RPC style agents. But a SOAP method call contains at least two data types: requests and responses. Consider this COM IDL code:

[UUID (deadf00d-bead-bead-bead-baabaabaabaa)] interface ibank: iunknown {

HRESULT WITHDRAW ([in] Long Account,

[OUT] Float * Newbalance,

[in, out] float * amount

[OUT, RETVAL] VARIANT_BOOL * OVERDRAWN);

}

Under any RPC protocol, the value of the Account and Amount parameters will appear in the request message, the NEWBALANCE, the OVERDRAWN parameter value, and the update value of the AMOUNT parameter will appear in the response message.

SOAP increases method requests and method responses to first-class state. In SOAP, request and respond to an instance of the actual type. To understand how a method is like Ibank :: withdraw maps a SOAP request and response type, consider the following data types:

Struct withdraw {

Long Account;

Float Amount;

}

This is a single request parameter being packaged into a single data type. The same below represents the package all response parameters to a single data type.

Struct withdrawresponse {

Float newbalance;

Float Amount;

Variant_bool overdrawn;

}

Then give the following simple Visual Basic program, it uses the previously defined IBANK interface:

Dim Bank As Ibank

DIM AMOUNT AS SINGLE

Dim Newbal As Single

Dim overdrawn as boolean

Amount = 100

Set bank = getObject ("soap: http://bofsoap.com/AM")

Overdrawn = Bank.withdraw (3512, Amount, Newbal)

You can imagine the underlying agent (possibly a SOAP, DCOM, or IIOP agent) looks like it is shown in Figure 8. Here, the parameter is serialized into a request object before transmitting the request message. The response object that is also the response message received by the response message is defined as a parameter. A similar transition also occurs in the calling server side.

When the method is called by the SOAP, the request object and the response object are seriallyified into a known format. Each SOAP body is an XML document that has a significant root element called . Marking Name By SOAP URI (URN: SCHEMAS-XMLSOAP-ORG: SOAP.V1), all SOAP dedicated elements and properties are defined by this URI. SOAP Envelope contains an optional

element that follows a must-have element. element also has a significant root element, or a request object or a response object. Below is an ibrok :: withdraw request code:

XMLns: SOAP = 'URN: Schemas-Xmlsoap-Org: SOAP.V1'>

'URN: UUID: Deadf00d-bead-bead-bead-baabaabaabaa>

3512

100

The following response message is encoded as:

XMLns: SOAP = 'URN: Schemas-Xmlsoap-Org: SOAP.V1'>

'URN: UUID: Deadf00d-bead-bead-bead-baabaabaabaa>

0

5

True

Note [IN, OUT] parameters appear in two messages.

After checking the format of the request and response object, you may have noticed the serialization format usually:

;

Field1Value

Field2Value

In the case of a request, the type is an implicit C style structure, which consists of [IN] and [IN, OUT] parameters in the corresponding method. In response, the type is also an implicit C style structure, which consists of [OUT] and [IN, OUT] parameters in the corresponding method. This style of each domain corresponds to a child element is sometimes referred to as an elemental format (ENF). In general, SOAP only conveys a comment that describes information contained in element content with an XML feature.

Like DCOM and IIOP, SOAP support protocol head extension. SOAP uses optional

elements to transmit information used by the protocol extension. If the client's SOAP software contains to send head information, the original request will might be shown in Figure 9. In this case, the header name will be serialized with the request. After receiving the request, the server-side software can view the headed name URI and process the head extension it identifies. This head extension is identified by http://comstuff.com URI and looks forward to a subject:

Struct causality {

UUID ID;

}

In this case, if the URI of the head element cannot be identified, the head element can be securely ignored.

But you cannot safely ignore the head elements in all SOAP. If a specific SOAP header is critical to properly handle the message, this header element can be marked with the SOAP attribute munderstand = 'true'. This attribute tells the recipient head element to be identified and processed to ensure proper use. In order to force the front Causality head to become a must-have, the message will be written as the following form:

XMLns: SOAP = 'URN: Schemas-Xmlsoap-Org: SOAP.V1'>

SOAP: MUSTUNDERSTAND = 'True'

XMLns = "http://comstuff.com">

362099CC-AA46-BAE2-5110-99AAC9823BFF

When the SOAP software encounters the case where the necessary header is not identified, the SOAP software must reject this message and present an error. If the server finds an unrecognized head element that cannot be identified in a SOAP request, it must return an error response and does not send any call to the target object. If the client finds a must-recognized head element that cannot be identified in a SOAP request, it must return a runtime error to the caller. (In the case of COM, this will map into a significant HRESULT) SOAP data type

In the SOAP message, each element may be a SOAP structure element, a root element, an access element or a separate element. In SOAP, SOAP: Envelope, SOAP: Body and SOAP: Header are the only three structural elements. Their basic relationships are described by the following XML Schema:

Targetnamespace = 'urn: schema-xmlsoap-org: soap.v1'>

Minoccurs = '0' />

Minoccurs = '1' />

In the four types of SOAP elements, in addition to the structural elements are used as an example of an expression type or a reference to a type of instance.

The root element is a significant element, it is a direct child element of SOAP: BODY or SOAP: Header. Soap: Body has only one root element, which expresss call, response, or error objects. This root element must be the first child element of SOAP: body, its tagname and domain name URI must correspond to the HTTP SOAPMETHODNAME head or SOAP: FAULT in the error message. The SOAP: Header element has multiple root elements, and each head extension is extended to each header. These root elements must be the direct child elements of SOAP: header, their tagname and name domain URI indicate the current existed data.

Access elements are used as domains, attributes, or data members of expression types. A given type of domain in its SOAP expression will have only one access element. The tag name of the access element corresponds to the domain name of the type. Consider the following Java class definitions:

Package com.bofsoap.ibank;

Public class adjustment {

Public int access;

Public float amount;

}

Examples of serialized in a SOAP message are as follows:

XMLns: T = 'URN: Develop-COM: Java: com.bofsoap.ibank'>

3514

100.0

In this example, access element Account and Amount are called simple access elements because they access Part 2 corresponding to the W3C XML Schema specification (see http://www.w3.org/tr/xmlschema-2). The value of the original data type defined in. This specification specifies the name and expression of the data types such as strings, values, and date and the use of the structure in a new mode definition to define a new original type of mechanism.

The access element of the reference is simple, and the element value is simply encoded to character data directly under the access element, as shown above. The access element of the reference combination type (which is the access element constructed by those own sub-access elements), there are two techniques to encode access elements. The easiest way is to embed the structured value directly under the access element. Consider the following Java class definition: package com.bofsoap.ibank;

Public class transfer {

Public Adjustment from;

Public Adjustment To;

}

If you encode an access element with an embedded value, a serial TRANSFER object in SOAP is shown below:

XMLns: T = 'URN: Develop-com: java: com.bofsoap.ibank'

>

3514

-100.0

3518

100.0

In this case, the value of the Adjustment object is directly encoded under their access element.

Several problems need to be explained when considering combining access elements. Consider the above TRANSFER class. The domain of the class from the class is an object reference, which may be empty. SOAP uses XML Schemas's NULL attribute to represent a null value or reference. The following example represents a serialized Transfer object, and its FROM domain is empty:

XMLns: T = 'URN: Develop-com: java: com.bofsoap.ibank'

XMLns: xsd = 'http://www.w3.org/1999/xmlschema/instance'

>

3518

100.0

In the absence of, the implies value of the XSD: Null property is False. The attribute of whether the given element is empty is controlled by the XML Schema definition. For example, the following XML Schema will only allow the FROM access element to be empty:

Name = 'from'

TYPE = 'Adjustment'

Nullable = 'true'

/>

Name = 'to'

TYPE = 'Adjustment'

Nullable = 'false'

/>

If there is no nullable attribute in the Schema declaration of an element, it means that the element in an XML document cannot be empty. The precise format of the NULL access element is currently revised & # 0; you should learn more about the latest version of the SOAP specification.

Another problem associated with the access element is due to the consequential displaceability caused by the type relationship. Due to the previous Adjustment class is not a final type of class, the Example of the TOM and TO domain actual reference inheritance types of the TRANSFER object is possible. To support this type of compatible replacement, SOAP uses an XML Schema appointed using a named domain. The value of this type of property is a name for the specific type of element. Consider the following Adjustment extension class: package com.bofsoap.ibank;

Public class auditedadjustment extends adjustment {

Public int Auditlevel;

}

Give the following java language:

Transfer XFER = New Transfer ();

XFer.from = new auditedadjustment ();

XFer.from.account = 3514; xfer.from.amount = -100;

XFer.from.auditlevel = 3;

XFer.to = new adjustment ();

XFer.to.account = 3518; XFer.from.Amount = 100;

The serialization form of the Transfer object in SOAP is as follows:

XMLns: xsd = 'http://www.w3.org/1999/xmlschema'

XMLns: T = 'URN: Develop-com: java: com.bofsoap.ibank'

>

3514

-100.0

3

3518

100.0

Here the XSD: Type property references a named domain name name, which can be used by the reverse serializer for instantiating the correct type of object. The XSD: Type property is unwanted because the TO access element is referenced to an example of an expected type (rather than an replaceable inheritance type).

Just now TRANSFER class tries to avoid a key issue. What happens if the Transfer object being serialized is initialized in this way:

Transfer XFER = New Transfer ();

XFer.from = new adjustment ();

XFer.from.account = 3514; xfer.from.amount = -100;

XFER.to = XFER.FROM;

Based on the previous discussion, the serialization form of the Transfer object in SOAP is as follows:

XMLns: T = 'URN: Develop-COM: Java: com.bofsoap.ibank'>

3514

-100.0

3514

-100.0

This expression has two problems. The problem that is the most easily understood is that the same information is sent twice, which leads to a larger message than the actual message. A more subtle but more important problem is that due to the different sequencer programs unable to distinguish between an Adjustment object with the same value and a single Adjustment object referenced by two places, the identity between two access elements The relationship is lost. If the message recipient has executed the following test on the result object, (XFer.to == XFer.from will not return TRUE.

Void ProcessTransfer (Transfer XFER) {

IF (xfer.to == xfer.from)

Handledoubleadjustment (xfer.to);

Else

Handleadjustments (XFer.to, XFer.from);

}

(XFer.to.Equals (xfer.from)) The fact that True may return TRUE is just a value of two access elements instead of their identity.

To support the sequence of the type of identity relationship, SOAP supports multi-reference access elements. At present, our access element is a single reference access element, that is, element values ​​are embedded under access elements, and other access elements are allowed to reference that value (this is similar to in NDR [[ Concept of UNIQUE]. Multi-reference access elements are always encoded to only a known SOAP: HREF attribute. SOAP: HREF attribute always contains a code snippet identifier, which corresponds to an instance referenced by an access element. If the To and the FROM access element have been encoded as multi-reference access elements, the serialized Transfer objects are as follows:

XMLns: T = 'URN: Develop-COM: Java: com.bofsoap.ibank'>

This encoding assumes that a type of type compatible with Adjustment class has been serialized elsewhere in Envelope, and this instance has been tagged with the SOAP: ID property, as shown below:

XMLns: T = 'URN: Develop-COM: Java: com.bofsoap.ibank'>

3514

-100.0

For multi-reference access elements, the identifier of the code segment (for example, # id1) is decomposed to the correct instance is the work of the reverse sequencer.

The previous discussion explains how multi-reference access elements are associated with its target instance. What is discussed below is that the target instance is serialized. This is related to the concept of independent elements and packages.

Independent element

In SOAP, a separate element represents an instance of a type of at least one multi-reference access element. All independent elements are tagged with the SOAP: ID attribute, and the value of this attribute must be unique in the entire SOAP Envelope. The independent element is encoded as if they are packaged by an access element, and the tagname of this access element is the type name of the name of the instance. In the above example, the type name of the name domain restriction of the instance is T: Adjustment.

SOAP limits independent elements to be encoded. SOAP defines an attribute that can be applied to any element: (SOAP: PACKAGE). This property is used to control the independent element to be decoded. SOAP serialization rules indicate that the independent element must be encoded as a SOAP: Header element or the direct child element of the body element, or any other marked as SOAP: package = 'true' element. By bringing an element to the package, you can ensure that the XML element encoding that instance is completely included, and there is no more reference access element that references this element other than this package. Suppose the Transfer class corresponds to a method request. If the TRANSFER type is not a package, the independent element referenced by TO and FROM access element will appear as the direct sub-element of the SOAP: body element, as shown in FIG. If the TRANSFER type is a legitimate SOAP package type, the encoding may be shown in Figure 11. Note that because the Transfer element is a package, all multi-reference accessor elements are referenced by the included elements. This makes the Transfer element as a separate XML code segment that can be separated from its parent elements easier.

Multi-reference access elements always refer to the model of independent elements is an exception. SOAP allows access elements containing strings and binary data to be more reference access elements. This means that the following code is legal:

Hello, SOAP

Although the fact is that the access element 2 has a SOAP: ID property, it is actually an access element instead of an independent element.

SOAP array

An array is encoded as a special example of a combined type. In SOAP, an array must have a rank (dimension) and a capacity. An array is encoded as a combination type, each of which is encoded as a child element, the name of this sub-element is the type name of the name domain restriction of the element.

Assume that there is a COM IDL type definition:

Struct PointList {

Long Celems;

[SIZE_IS (CELEMS)] Point Points [];

}

This type of instance will be sequenced:

3

3

SOAP: OFFSET = '[1]'>

lt; x> 1 lt; y> 9 lt; / point>

The SOAP: OFFSET property indicates the index of the first element in the array. In the example above, elements 0, 2 to 4 are not converted. SOAP also supports sparse arrays, which is achieved by using the SOAP: Position attribute to annotate each element with its absolute index:

lt; x> 3 lt; y> 4 lt; / point>

lt; x> 4 lt; y> 5 lt; / point>

In this example, elements 0 to 2, 4 to 6, and 8 to 9 are not converted.

Note that the exact syntax in the SOAP in the SOAP is still being re-examined in this article writing to adjust to the upcoming W3C XML Schema specification. To constantly understand the latest version of the SOAP specification to get more details.

Error handling

A server sometimes does not correctly request a service to request. This may be due to a general HTTP error (such as request -uri cannot be mapped to the local resource or a HTTP level security violation). It may also be a problem in SOAP translation software, such as Marshall packaging errors or a must not be recognized. Other possible reasons include a request not to be served correctly, or an application / object code decide to return an error to the caller. These conditions are cleared in the SOAP specification.

If an error occurs in the HTTP layer before distributing the call to any SOAP code, a pure HTTP response must be returned. The standard HTTP status code number will be employed, and the 400-level code represents a customer-triggered error, and the 500-level code represents an error triggered by the server. This usually automatically handles by the web server software before code execution.

Assuming that everything in the HTTP layer is normal, the next place that happens is to call the SOAP call for application code (such as COM objects and CORBA servo objects). If the error occurs at this layer, the server must return an error message instead of a standard response message. An error message is an instance of the type of root element encoded as SOAP: body.

Targetnamespace = 'urn: schema-xmlsoap-org: soap.v1'

>

The FaultCode Access element must contain a value of SOAP error code represented by a known integer or a value of a specially applied name domain. The current SOAP error code is shown in Figure 12. Faultstring Access elements contain a description of the readability of the error that occurs. The Runcode Access element contains a string that must be YES, NO or Maybe, indicating whether the requested operation is actually performed before the error is generated. The Detail Access element is optional and is used to include an exception object specifically applied.

Below is an example of a SOAP error corresponding to a request that contains unrecognized head elements:

XMLns: soap = 'urn: schema-xmlsoap-org: soap.v1'

>

;

200

Unrecognized 'Causality' Header

no

Assuming that the specific application's error needs to be returned, you may see the code as shown in Figure 13. In the case of applying defined errors, the Detail Access Element plays a SOAP: Body element when considering the exception / error object of the application.

Mystery

An legacy HTTP issue also needs to be further clarified. SOAP support (but not required) HTTP extension framework is scheduled to specify a must-have HTTP header extension. These conventions have two main purposes. First, they allow any URI to be used to define a range of given HTTP headers (like XML names). Second, these conventions allow for distinguishing the necessary heads to the optional headers (like SOAP: MUSTERSTAND). Below is a HTTP extension framework to define the soapMethodName header into a must-have-headed extension:

M-post / foobar http / 1.1

Host: 209.110.197.2

MAN: "URN: Schemas-Xmlsoap-Org: soap.v1; ns = 42"

42-SOAPMETHODNAME: URN: BOBNSID: IFOO # DOIT

The MAN header maps the SOAP URI to the head of 42 and indicates that the server that does not recognize SOAP must return an HTTP error, and the status code is 501 (not implemented) or 510 (not expanded). The HTTP method must be M-POST, indicating that it is currently a must-have extension.

in conclusion

SOAP is a typed serialization format, which happens to use HTTP as a request / response message transfer protocol. SOAP is designed to closely cooperate with the XML Schema specification that is displayed and supports COM, CORBA, Perl, TCL, and Java-Language, C, Python, or PHP and other programs. .

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

New Post(0)