This article explains how you can execute the web service via HTTP GET method.
Introduction
When we create any web service via Vistual Studio, by Default it gets executed via HTTP Post. This article explains how we can configure our web service so it runs on both the method that is GET and POST.
Demonstration
When we created any web service via Vistual Studio, we always get a default method named “Hello world”.
When you hit this URL in your browser, http://localhost/SampleWebService/Service.asmx, it shows list of all the web method. Click on Hello World and then Invoke. It gives following output:
I am assuming that you have hosted your web service in IIS.
<?xml version="1.0" encoding="utf-8" ?>
<string xmlns="http://tempuri.org/">Hello World</string>
Looks good. Now let’s go and modify our service.cs file and add a new method which takes one parameter.
[WebMethod]
public string HelloWorldWithParam(int a)
{
return "Hello World " + a.ToString();
}
Now, hit this URL http://localhost/SampleWebService/Service.asmx. It is showing both the methods.

Click on HelloWorldWithParam. It asks for parameter value. Without giving any value just click invoke.

It shows following error:

Above error is coming as method is expecting a value, and method tries to convert null value to string. If you refresh your browser or try to modify the URL by adding querystring then also following error comes:

Now let’s provide the parameter value via URL only. Hit this URL, http://localhost/SampleWebService/Service.asmx/HelloWorldWithParam?a=1 , and then also you will receive the above error.
Reason: By default, Web service created via Visual Studio executes through HTTP Post method. When Post method is used, querystring is not visible. We need to configure our web service, so it works with HTTP GET and POST method. How can we do this?
Go to web.config and add this code in system.web section.
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
Good to go now. Hit this URL again and this time you will see “Hello World 1”.
Enjoy….