Application and implementation of SOAP protocol expansion

xiaoxiao2021-03-06  108

Application and implementation of SOAP protocol expansion

The SOAP protocol (simple object transmission) is an XML-based, simple lightweight protocol for exchange structured and type information on the web. The overall design goal of SOAP is to make it simply as possible and provide the least functionality. This protocol defines a messaging framework that does not contain any application or transmit semantics. Therefore, the protocol is modular and has strong spreadability.

The SOAP protocol specification contains four main components. The first part defines the necessary scalable envelopes for packaging data. The SOAP envelope defines the SOAP message and is the basic exchange unit between the SOAP message processor. This is the only part of this specification.

The second part of the SOAP protocol specification defines the data type defined by the application and an optional data coding rule for graphics, and a unified model for serializing non-syntax data models.

The third part defines the message exchange mode of the RPC style (request / response). Each SOAP message is one-way transmission. Although the root of SOAP is in RPC, it is just just a request / response mechanism. XML Web Services often combines SOAP messages to implement such patterns, but SOAP does not force message exchange mode, which is also optional.

The fourth part of the specification defines the binding between SOAP and HTTP. However, this part is also optional. SOAP can be used with any transport protocol or mechanism (including SMTP FTP or even floppy disk) capable of transmitting a SOAP envelope.

Microsoft implements a SOAP protocol and makes it an important basis for .NET Framework. Any Client-Server-based transmission of Microsoft.NET is in the form of SOAP. (HttpGet and Httppost protocols are just Client applications).

Have an example of .NET. For example, a Web Service program is DATA.ASMX:

<% @ Webservice Language = "C #" class = "data"%>

Using system;

Using system.Web.services;

Public Class Order

{

Public int OrderID;

Public Double Price;

}

Public class data {

[WebMethod]

Public Order GetOrder ()

{

Order myorder = new order ();

myorder.price = 34.5;

Myorder.orderid = 323232;

Return myorder;

}

}

Now use the WSDL tool to convert Web Serivce's WSDL to Client agents such as WSDL / Protocol: SOAP / NAMESPACE: D http://localhost/data1.asmx

(Suppose Data1.asmx is placed under the root of the IIS server (C: / INETPUB / WWWROOT)).

Generate a client agent Data.cs:

Namespace d {

Using system.diagnostics;

Using system.xml.serialization;

Using system;

Using system.web.services.protocols;

Using system.componentmodel;

Using system.Web.services;

///

[System.diagnostics.debuggerstepthroughattribute ()]

[System.componentmodel.designercategoryAttribute ("code")]]]]]

[System.Web.Services.WebserviceBindingAttribute (name = "datasoap", namespace = "http://tempuri.org/")] public class data: system.Web.Services.protocols.soaphttpClientProtocol {

///

Public Data () {

THIS.URL = "http://localhost/data1.asmx";

}

///

[System.Web.Services.Protocols.SoapDocumentMethodAttribute ( "http://tempuri.org/GetOrder", RequestNamespace = "http://tempuri.org/", ResponseNamespace = "http://tempuri.org/", Use = System.Web.Services.Description.soapbindinguse.literal, parametersty = system.web.services.protocols.soApparameterStyle.wrapped]

Public Order GetOrder () {

Object [] results = this.invoke ("getorder", new object [0]);

Return ((ORDER) (Results [0]));

}

///

Public System.iasyncResult BegingeTorder (System.AssyncCallback Callback, Object AsyncState) {

Return this.beginInvoke ("GetOrder", New Object [0], Callback, AsyncState;

}

///

Public Order Endgetorder (System.iasyncResult asyncRESULT) {

Object [] results = this.endinvoke (asyncResult);

Return ((ORDER) (Results [0]));

}

}

///

[System.xml.serialization.xmltypeattribute (Namespace = "http://tempuri.org/")]

Public class order {

///

Public int OrderID;

///

Public system.double price;

}

}

Then compile it into a DLL. Such as: CSC / T: library /out:c:/inetpub/wwroot/bin/data.dll data.cs, ​​you can use .NET's Client program to call (such as Winform, CS or aspx).

Here is the call to the client with Test.aspx.

<% @ Import namespace = "d"%>