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
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:
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:
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.
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.
Enter name in the name textbox and click invoke button. It will open up new window where the response will be rendered as XML.