来源:https://www.codeproject.com/Articles/11878/SOAP-in-NET-Framework
SOAP 1.2 in .NET Framework 2.0
Introduction
SOAP version 1.2 (SOAP) is a lightweight protocol intended for exchanging structured information in a decentralized, distributed environment. It uses XML technologies to define an extensible messaging framework providing a message construct that can be exchanged over a variety of underlying protocols. The framework has been designed to be independent of any particular programming model and other implementation specific semantics.
The technological foundation that makes up Web services includes SOAP, the Web Service Description Language (WSDL), Universal Description, Discovery, and Integration (UDDI), and XML. Specifically, SOAP provides a heterogeneous mechanism to allow the invocation and communication between Web services.
Some of the shortcomings of the SOAP 1.1 has been clarified, updated and corrected in SOAP 1.2. SOAP 1.2 contains a number of issues such as those on interoperability and ambiguities that resulted in differences of interpretation.
SOAP 1.1 is based on XML 1.0 and can only use HTTP POST headers to transmit SOAP messages. As a result, it isn't really suitable for wide-scale applications.
SOAP 1.2
SOAP 1.2 provides a tighter, more robust set of specifications based on an abstract model for binding protocols and XML serialization schemes. SOAP 1.2 also has been tested by a wide variety of participants, including IBM, Microsoft, Sun Microsystems, BEA systems, and the Apache Software Foundation. It has undergone many reviews and drafts and has seen a tremendous amount of public feedback. The W3C tested the interoperability of the specifications by successfully implementing seven projects.
SOAP 1.2 is now extensively documented in three parts: a Primer, Complete Messaging Framework, and Model and Optional Add-ins. SOAP 1.2 is now defined as an XML infoset, not XML syntax.
SOAP Version Information
- SOAP 1.1
- SOAP 1.2
Comparison between SOAP 1.1 and SOAP 1.2
- SOAP 1.1 is based on XML 1.0; SOAP 1.2 is based on XML Infoset.
- In SOAP 1.2 it is left to the specification of a binding to an underlying protocol to specify the XML serialization used in the underlying protocol data units.
- The HTTP binding specified in SOAP 1.2 uses XML 1.0 as the serialization format of the SOAP message infoset.
- SOAP 1.1 allows additional elements to follow the SOAP Body element, SOAP 1.2 disallows these.
- SOAP 1.1 has the actor attribute. In SOAP 1.2 this attribute is renamed to role. The semantics of the attribute are unchanged.
- SOAP 1.2 adds two new predefined roles to the existing "Next" role in SOAP 1.1:
- "None" for header blocks that should never be directly processed.
- "Ultimate Receiver" for header blocks that should only be processed by nodes acting as the ultimate receiver of a message.
- HTTP GET support
Carrying of a SOAP 1.1 message was discussed using only HTTP POST. SOAP 1.2 adds support for the use of HTTP GET in the SOAP HTTP binding. The semantics of HTTP GET are respected such that the action performed by SOAP endpoint responding to a request transmitted via HTTP GET should be both safe and idempotent.
Rules for dealing with SOAP 1.1 and SOAP 1.2 version interactions are as follows:
- When a SOAP 1.2 message reaches a SOAP 1.1 node it will generate a SOAP fault containing a version mismatch.
- When a SOAP 1.2 node receives a SOAP 1.1 message it can do one of the two things as stated below:
- The node may process the SOAP 1.1 message.
- It generates a Fault containing a Version Mismatch.
SOAP 1.2 in .NET Framework 2.0
The new ASMX runtime in .NET 2.0 supports SOAP 1.2. At this moment SOAP 1.1 is most widely being used in the industry. In the .NET Framework both SOAP 1.1 and SOAP 1.2 are supported. This means that the Web Services created in .NET Framework 2.0 will be configured to support both SOAP 1.1 and SOAP 1.2 messages. This indirectly means that the WSDLs thus created for the Web Service will have two types of bindings, i.e., SOAP 1.1 and SOAP 1.2.
<wsdl:binding name="ServiceSoap12" type="tns:ServiceSoap">
<wsdl:binding name="ServiceSoap" type="tns:ServiceSoap">
Whether both these bindings have to be added to the web service can be configured by enabling or disabling them from the web.config file.
<configuration> <system.web> <webServices> <protocols> <remove name="HttpSoap12"/> </protocols> </webServices> </system.web> </configuration>
Replace "HttpSoap12" with "HttpSoap" to remove the SOAP 1.1 binding.
The enumeration value must be one of the following: Unknown
, HttpSoap
, HttpGet
, HttpPost
, Documentation
, HttpPostLocalhost
, HttpSoap12
, AnyHttpSoap
.
Creating a SOAP 1.2 Web Service in Microsoft Visual Studio 2005 Beta 2
- Click on “File—New—Web Site”.
- Select folder “E:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\WebServices\WebSite1”.
Here we can use IIS (then we need to specify HTTP in the Location dropdown list). Visual Studio 2005 supports internal server, thus IIS is not required. We can use the test server. It is known as the file system.
- Select language as C#.
- Open the Service.cs file.
- Namespaces that are included are:
Hide Copy Code
using System; using System.Web; using System.Web.Services; using System.Web.Services.Protocols;
- Create a WebMethod:
Hide Copy Code
[WebMethod] public long CheckBalance(int iAccountNo) { //Business Logic...... //return balance return iBalance; }
- Now edit the web.config file to allow or disallow various protocols used for invocation as described above.
- Go to the WebService properties and turn off NTLM authentication.
- Build the solution
SOAP request and response
SOAP 1.1

Request:
POST /WS1/Service.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/CheckBalance"
<?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>
<CheckBalance xmlns="http://tempuri.org/">
<iAccountNo>int</iAccountNo>
</CheckBalance>
</soap:Body>
</soap:Envelope>
Response:
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>
<CheckBalanceResponse xmlns="http://tempuri.org/">
<CheckBalanceResult>long</CheckBalanceResult>
</CheckBalanceResponse>
</soap:Body>
</soap:Envelope>
SOAP 1.2

Request:
POST /WS1/Service.asmx HTTP/1.1
Host: localhost
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<CheckBalance xmlns="http://tempuri.org/">
<iAccountNo>int</iAccountNo>
</CheckBalance>
</soap12:Body>
</soap12:Envelope>
Response:
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<CheckBalanceResponse xmlns="http://tempuri.org/">
<CheckBalanceResult>long</CheckBalanceResult>
</CheckBalanceResponse>
</soap12:Body>
</soap12:Envelope>
WSDL (binding elements)
<wsdl:binding name="ServiceSoap" type="tns:ServiceSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="CheckBalance">
<soap:operation
soapAction="http://tempuri.org/CheckBalance" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="ServiceSoap12" type="tns:ServiceSoap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="CheckBalance">
<soap12:operation
soapAction="http://tempuri.org/CheckBalance" style="document" />
<wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
Client Side
On the client side, WSDL.EXE generates SOAP 1.1 proxy code by default. There is a /protocol command line option to WSDL.EXE that allows you to specify which version to use. /protocol:SOAP generates a SOAP 1.1 client and /protocol:SOAP12 generates a SOAP 1.2 client:
C:\>wsdl /o: proxy.cs /protocol:SOAP http://localhost:2881/WS1/Service.asmx Microsoft (R) Web Services Description Language Utility [Microsoft(R) .NET Framework, Version 2.0.40607.85] Copyright (C) Microsoft Corporation. All rights reserved. Writing file 'proxy.cs'. C:\>wsdl /o: proxy12.cs /protocol:SOAP12 http://localhost:2881/WS1/Service.asmx Microsoft (R) Web Services Description Language Utility [Microsoft(R) .NET Framework, Version 2.0.40607.85] Copyright (C) Microsoft Corporation. All rights reserved. Writing file ‘proxy12.cs'. C:\>
The System.Web.Services.Protocols.SoapHttpClientProtocol
class that is used as the base class of the generated client proxies has a new property SoapVersion
. This is set to SoapProtocolVersion.Soap12
to indicate that SOAP 1.2 should be used. The correct binding name is also chosen from the WSDL.
License
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
2017-04-21 开发APP不搞清楚这20个问题,必然沦为一场灾难
2017-04-21 全是干货!UI设计的30条黄金准则!