public knowledge blog_load(sender Virendra)

                                                                                                                          Nothing shocks me, I am a Software Engineer.

Execute Web Service via GET Method

Posted by Virendra Dugar on September 8, 2009

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=”“>Hello World</string>

Looks good. Now let’s go and modify our service.cs file and add a new method which takes one parameter.

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 then 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.

        <add name=”HttpGet”/>
        <add name=”HttpPost”/>

Good to go now. Hit this URL again and this time you will see “Hello World 1”.



One Response to “Execute Web Service via GET Method”

  1. JimmyBean said

    I don’t know If I said it already but …Excellent site, keep up the good work. I read a lot of blogs on a daily basis and for the most part, people lack substance but, I just wanted to make a quick comment to say I’m glad I found your blog. Thanks, 🙂

    A definite great read..Jim Bean

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: