I’m trying to make a web service that would respond to HttpGet and HttpPost requests differently.
I have enabled HttpGet with this:
<webServices>
<protocols>
<add name="HttpGet"/>
</protocols>
</webServices>
And I created 2 functions, one that should be fired for HttpPost request and the other – on HttpGet:
[WebMethod]
[HttpPost]
[ActionName("HelloWorld")]
public string HelloWorldPost()
{
return "Hello POST World";
}
[WebMethod]
[HttpGet]
public string HelloWorld()
{
return "Hello GET World";
}
However it seems that HttpGet, HttpPost and ActionName get ignored completely. All requests to HelloWorld (post or get) fire the second function. Do I need to do this some other way? I also tried to limit the functions with this:
[ScriptMethod(UseHttpGet = false)]
But that also made no difference.
ASP.NET Web Service Application behave differently than ASP.NET MVC, which is along the lines of your expectations. In your code, both HttpGet/HttpPost and ActionName attributes belong to MVC as noted by Amiram Korach. Those attributes are ignored when hosted as a web service application.
“Routing” in web service application is based on the method name (HelloWorldPost and HelloWorld) and not based on HTTP VERB.
To trigger the POST flow, you have to invoke
HelloWorldPost(service.asmx/HelloWorldPost)