Creating this post especially for my friend. Who want to learn How to create His First Web Service. If you too want to do the same then go ahead and start your visual studio.
Service
-
Click on Web Site Project

-
It will open New Web site Dialog box. Choose ASP.NET web service and give it appropriate name(HelloWorldService) and select your Coding language(C#). Click OK.
It will take some time because it will make everything ready for you sir. So, you can start quickly

-
What it has created?

Service.cs: is the main file where you can write you code. E.g application logic etc..Calling Data Access layer etc.
Service.asmx will expose your service to outer world.
-
Web Method
If you will see Service.cs it has one method already written. You can use it as a reference implementation
[WebMethod]
public
string HelloWorld() {
return
“Hello World”;
}
Any method you want to expose you have to declare it by attribute WebMethod
Let’S create our new method.So, you can get more into methods.
Just copy paste above one and modify it will like this:
///
<summary>
/// This method will take argument as a string and show it with greeting
///
</summary>
///
<param name=”name”></param>
///
<returns></returns>
[WebMethod]
public
string
MyHelloWorld(string name)
{
return
“Hello World,”+name;
//Here you can call your Insert,Update,Delete from DAL and write return statement
}
- Build Web Site [CTRL+SHIFT+B]. That’s it we have our service Ready. Let’s create one consumer for it.
Consumer
Our Service is ready. It will take name and return it with Hello World name. I am creating here one Windows application for demo. You can create any client to use it.[That's why it is service
]
1. Click on your solution file name Means [Your focus should be on C:\HelloService or your solution name]

2. Select File | Add | New Project

3. It will open Add New Project Dialog Box. Select Windows application and give appropriate name to it. Click OK

4. So now you will have structure as under:

5. Right Click on HelloWorldConsumer project and Click on Add Web Reference- For Adding service reference.

6.It will open Add Web Reference window. Just click on Web Services in this solution. Because we have our service under same solution.

7. It will find out service. Just click on it.

8. It will load our methods as shown here: [Web reference name I had changed "localhost" to "HelloWorldClient". So you should also do it. Its good practice]. Click on Add reference button. – Which will add our service reference to client.

9. Now your soln structure should look like:

10. Click on Form1 and drag some controls so we can test it. So, your form should look like this.

11. Double click on “Call Service” Button it is Buttton1 for me. For creating its Click event handler code. And it will point it to handler code call your service here and show result in Messagebox as shown here.


12. Build solution. And ensure that HelloWorldConsumer-windows application is your startup project. Then run the project [CTRL+F5]

13. looks Cool… It’s working man. Try with your name and enjoy!!!
Links:
http://quickstarts.asp.net/QuickStartv20/webservices/
http://www.w3schools.com/webservices/default.asp
Happy Service Coding!!!
I have also kept solution here for reference. But I request you first try yourself and if get some error then and then try this. Pls try to do it yourself first. you can download it from Here
Update:
Add Reference in VS 2008 — http://www.carlosfemmer.com/post/2008/01/How-to-add-web-reference-in-VS-2008-Project.aspx
Thanks to Ravindra Joshi for pointing it out!