Hello World Web
Service in Visual C#
This page assumes that the Visual Studio .Net 2003 version
is installed with all default options.
Visual Studio makes Web service development very simple
process.
Hello World :
We will create a Hello World Web Service that will have only
one method named ‘Hello World’ .
The client of this application can call this service by
using SOAP or HTTP-GET or HTTP-POST request, the service replies with a string
message “Hello World’.
Step I:
- Start
Visual Studio .Net IDE.
- Use
File menu, then click New Project.

- Use C#
from Project Types, then select “ASP .NET Web Service” from Templates.
- Use
the name HelloWorld in the Location. The full path defines the location of
files that IIS server uses for this service.
- Click
OK.
Step II:
- After
Visual Studio generates the template of the project, edit the code. Use View-> Solution Explorer window.
Right-click ok on Service.asmx.
Note the code file that is opened has the .cs extension for C#.
- Find
the following section towards the end of the file and uncomment the lines
[WebMethod]
public string HelloWorld()
{
return "Hello
World";
}
- Use
‘Build Solution’ option from build menu to build the solution.
Step III:
- Test
the Web Service that we built just now. Press F5 to Start the Web Service
from within the Visual Studio. This will open up the Internet Explorer
with the URL used to build the Service
“http://localhost/XMLWebServices/Tutorial/HelloWorld/Service1.asmx”.
- The
page displays the description about the Web service and proper use of “Namespace”.

- Click
the HellowWorld method on the top of the page. This will display the
details of the Hello World method. This includes the section that shows
the structure of SOAp or HTTP-GET and HTTP-POST requests to the service.
The highlighted parts indicate that they are variable at runtime.

- Click
on Invoke button. This will invoke the Web Service using HTTP-GET
protocol. The response will be:
<?xml version="1.0" encoding="utf-8" ?>
<string xmlns="http://tempuri.org/">Hello World</string>
This response is not for end-user. This is a response to the
Web Service client for it’s internal use. But you can see the text “Hello
World’.