我正在进行研究,下载了一个调用标准.asmx服务的测试应用程序。该服务使用标准的POST请求进行调用。我有些困惑,因为我认为.asmx服务总是使用SOAP协议?还是最近才引入了与HTTP(POST)通信的功能?
我正在进行研究,下载了一个调用标准.asmx服务的测试应用程序。该服务使用标准的POST请求进行调用。我有些困惑,因为我认为.asmx服务总是使用SOAP协议?还是最近才引入了与HTTP(POST)通信的功能?
[ScriptMethod(UseHttpGet = true)]
public string MyMethod()
{
return "Hello World";
}
.NET Web服务使用您选择的一种协议。默认情况下是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
SOAP是一种标准,您可以选择使用它。它基于XML。如果是一些简单的东西,那么我会使用JSON。Web服务不仅限于POST。当您运行创建/更新/删除例程时,应该使用POST,而在运行数据检索例程时应该使用GET。