Related Posts Plugin for WordPress, Blogger...

How To Call A Web Service in C#.Net

How To Call A Web Service in C#.NetI have posted previously an article on how to create a web service, this time we are going to call the web service in our web applications. The first thing you need to know is the URL of the Web Service (e.g. http://localhost:2760/HelloWorld/HelloWorld.asmx). After that, you can open your existing web application and add a web reference. You can use web service by the way in any programming language (VB.Net or C#.Net).

To add the web reference, at the Solution Explorer, right click the Main project then select Add Web Reference. You will be prompted to enter the URL. Enter the URL of the web service of Hello World then click the Go button. A preview of the web service will be shown on the left part of the screen. At the Web Reference name, supply your desired name then click the Add Reference button. Your “Hello World” web reference should now be located in the App_WebReferences folder. It will contain three files with file extensions disco, discomap and wsdl.

Now to call the web service, add this code after the public class:

In this example, the web reference is named “Hello World” and we declare it as “_Service.”

After the proper declaration and adding of web reference, we can now call the web service method. Use the following codes below:

On the first line, we set a new value to the _ServiceErr. The next line is the passing of the string “Makoy” to the web service method named “Hello World.” Upon passing the value “Makoy” to this method, it will now show a message, “Hello Makoy!”

If you like this post, buy me a cup of coffee.

Share This Post Digg This Furl Reddit Fav This With Technorati Yahoo MyWeb Stumble This


  1. webbielady  

    February 25, 2009 at 11:40 PM

    This is cool and helpful. I think I got to try this. Useful tutorial you did there.

    336th BigMak Contest point for WebbieLady

  2. Hi! I'm Grace  

    February 26, 2009 at 7:31 AM

    Thanks for this very informative post, Makoy. :)

  3. Sherry  

    February 26, 2009 at 11:14 AM

    this is good info. Might come in handy :)

  4. Denis  

    February 26, 2009 at 2:09 PM

    im sure all IT people out there or even ordinary folks will be delighted with this article

  5. Sherry  

    February 26, 2009 at 3:44 PM

    tweet this

  6. Webbielady  

    February 26, 2009 at 11:38 PM

    Twittered this post as well over here:

  7. Webbielady  

    February 27, 2009 at 9:56 PM

    The fifth to digg this here as webbieladycont leaving the following comment: "Helpful advice/instruction for those who plan to do this web service thingy.."

  8. Sherry  

    March 10, 2009 at 5:57 PM

    I am never good in programming and I know its important to read up

  9. Rolly  

    March 11, 2009 at 3:11 AM

    Absolutely educational. I like it.

    Dugg this, twitted and make a comment.

  10. Anonymous  

    November 10, 2009 at 3:19 PM

    U surely deserve coffee!!! - Cheap domain name registration, renewal and transfers - Free SSL Certificates - Web Hosting