Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable ASP.NET ASMX web service for HTTP POST / GET requests

I would like to enable a ASP.NET classic (ASMX) web service for HTTP POST and GET requests. I realise this can be done on a machine or application level by adding ...

<webServices>     <protocols>         <add name="HttpGet"/>         <add name="HttpPost"/>     </protocols> </webServices> 

.. to the machine.config or web.config. My question is can HTTP POST and GET requests be enabled per web service or web method level rather than per application or machine?

My web service is written in c# using net 3.5sp1.

like image 965
Dean Bates Avatar asked Mar 06 '09 13:03

Dean Bates


People also ask

How do I add Asmx to my web service?

For your requirement, please view the document to add Web Service (ASMX) file in VS 2019: right-click your project > Add > New Item… > search Web Service (ASMX) > click on Add . If the answer is helpful, please click "Accept Answer" and upvote it.

How do I contact Asmx service?

Adding Reference of the Web Service in Visual Studio 1. Right click the project in Solution Explorer and choose Add Service Reference option from the context menu. 2. Now in the Add Service Reference Dialog you need to click on the Advanced button.

Does Asmx use soap?

ASMX provides the ability to build web services that send messages using the Simple Object Access Protocol (SOAP). SOAP is a platform-independent and language-independent protocol for building and accessing web services.


2 Answers

Try to declare UseHttpGet over your method.

[ScriptMethod(UseHttpGet = true)] public string HelloWorld() {     return "Hello World"; } 
like image 95
tanathos Avatar answered Sep 18 '22 08:09

tanathos


Actually, I found a somewhat quirky way to do this. Add the protocol to your web.config, but inside a location element. Specify the webservice location as the path attribute, like so:

<location path="YourWebservice.asmx">   <system.web>     <webServices>       <protocols>         <add name="HttpGet"/>         <add name="HttpPost"/>       </protocols>     </webServices>   </system.web> </location> 
like image 23
BLΞND OnLine Avatar answered Sep 20 '22 08:09

BLΞND OnLine