开发者

Does a .net 2.0 web service always use Soap over http?

Im doing research and I downloaded a test app that calls a standard .asmx service. The service is being called using a sta开发者_运维问答ndard POST request. Im slightly confused because I thought .asmx services always used SOAP? Or is the ability to communicate with HTTP (POST) something that was introduced recently?


.NET Web-Services uses the one protocol you choose. By deafult it is the SOAP, and POST requests are allowed.

Standart help page automatically created by .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>

Also you can enable the GET method:

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

This works from .NET 1.1


No, ASMX webservices are not limited to SOAP. You can use the ScriptMethodAttribute to specify the a HTTP verb for a webmethod. This was introduced in .Net 3.5. For example:

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


SOAP is a standard that you may choose to use. It's based on XML. If it's something simple, than I'd use JSON. Web services are not limited to POST. You should be using POST when you run Create/Update/Delete routines and you should use GET when you run data retrieval routines.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜