2011-06-09 48 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"; 
}