• How to use or consume a web service in C#

    by  • May 29, 2013 • Microsoft .NET C# (C-Sharp), Microsoft .NET Web Services, Microsoft ASP.NET • 0 Comments

    In one of my previous articles, I have explained briefly about what the web service is and how we can create a web service in ASP.NET. When a web service is created, the next step is to learn how we can use this web service. Well, sometimes we just need to learn how to consume web services created by others. That is the whole purpose of the web service. They are created to be used by other applications. So this article will explain how we can use a web service.

    The first step to use a web service is to add the reference of that web service in your application. You need to copy the URL of the web service which you want to use and follow below steps. For this article, I am using web service which I have created in my previous article.

    Select Add Service Reference from Web Site

    Then Select Advanced and then Add Web Reference

    Enter URL, change the name of web service and click Add Reference

    UseWebService

    Now you need to use web service namespace in your code file. The namespace will be the name of your web service.

    Now you can call web methods of web service in your code by creating an instance of that web service. It is same like you use any class in your code. You need to create the instance of that class and then call the methods of that class. I have called both web methods of my web service.

    You have to remember few things when creating new web methods in your web service. First of all they should be web methods with “Web Method” keyword at the top. Second, they should be declared “public” so that they can be accessed publically. And last but not least, you must need to rebuild solution of your web service when you have created a new web method and you want to make that web method available to the users of web service.




    Namecheap.com
    Avatar of GetCodeSnippet.com

    About

    GetCodeSnippet.com provides you high quality Microsoft .NET development related articles, tutorials and sample code for ASP.NET, C#, VB.NET, AJAX, WCF, WPF, Web Services, Windows Services, SQL Server and other technologies.

    Leave a Reply