2011-06-09 118 views
3

我正在做研究,我下载了一个测试应用程序,调用标准的.asmx服务。该服务正在使用标准的POST请求进行调用。 Im有点困惑,因为我认为.asmx服务总是使用SOAP?或者是与最近推出的HTTP(POST)进行通信的能力?.net 2.0 web服务是否总是使用soap over soap?

回答

1

.NET Web-Services使用您选择的一种协议。由default它是SOAP,和POST请求被允许。

由.NET自动创建

斯坦达特的帮助页面:

POST /demo/MSDN/PerfCounter.asmx HTTP/1.1 
Connection: Keep-Alive 
Content-Length: 150 
Content-Type: text/xml 
Host: localhost 
User-Agent: MS Web Services Client Protocol 1.0.2204.19 
SOAPAction: "http://tempuri.org/PerfCounters" 

<?xml version="1.0"?> 
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
       xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
       xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" 
       xmlns:xsd="http://www.w3.org/1999/XMLSchema"> 
    <soap:Body> 
    <PerfCounters xmlns="http://tempuri.org/"/> 
    </soap:Body> 
</soap:Envelope> 

您也可以启用GET方法:

<configuration> 
    <system.web> 
    <webServices> 
     <protocols> 
      <add name="HttpGet"/> 
      <add name="HttpPost"/> 
     </protocols> 
    </webServices> 
    </system.web> 
</configuration> 

这个工作从.NET 1.1

0

SOAP是您可以选择使用的标准。它基于XML。如果它是简单的,比我会使用JSON。 Web服务不限于POST。运行创建/更新/删除例程时应使用POST,并且在运行数据检索例程时应使用GET。

1

不,ASMX web服务不限于SOAP。您可以使用ScriptMethodAttribute为web方法指定HTTP谓词。这是在.NET 3.5中引入的。例如:

[ScriptMethod(UseHttpGet = true)] 
public string MyMethod() 
{ 
    return "Hello World"; 
}