How to create webservice in asp.net using csharp

In this post we are going to discuss about how to create webservice in asp.net using C# programming language. You just follow below given steps to create simple hello world webservice using C# in visual studio IDE.

Step 1: Create a project

Open visual studio >> Select File >> New >> Web Site >> Select ASP.NET Web Service
webservice_img_1

Step 2: Check folder Structure

Webservice has been created and visual studio would create configuration files and other files by default but make sure the files are created without any issues and no file is missing. Webservice folder structure would look like:
webservice_img_2

Step 3: Add/update web methods in Service.asmx

Open Service.asmx, it would have default web method ‘HelloWorld’ created. Let us change the web method name to ‘sayHello’ and this method will accept one parameter which is going to be String. The method will return text ‘Hello’ appended with the String passed as parameter to it.
After the code changes, the Service.asmx will look like:
webservice_img_3

Step 4: Run Webservice

Let us run the webservice we created. Click on ‘Start Debugging’ button or press ‘F5’, select Run without debugging. It will open up browser where the Service we created will be rendered under the URL: http://localhost:23027/SampleService/Service.asmx.
webservice_img_4

Step 5: Test Webservice

It’s time to test the webservice we created, click ‘sayHello’ operation. It will open a web page the webmethod invocation can be done.
webservice_img_5
Enter name in the name textbox and click invoke button. It will open up new window where the response will be rendered as XML.
webservice_img_6

Author: Udhay

Share This Post On
  • Gobinda

    This is good for webservice

  • anamika

    this website is cool! informative

  • Digital Sagotharan

    Nice Step by step process. It will help the beginners too.

  • http://programmerguru.com/ Android Guru

    Thank you.

Pin It on Pinterest

Shares