Creating a basic Web Service
A lot can be found on the internet regarding web services. Here am just gonna create a basic Web Service using ASP.Net/C#:
1. Run your Microsoft Visual Studio 2005
2. Create a new ASP.Net Web Service from File > New > Web Site > ASP.Net Web Service
3. Choose the language of your choice, enter a project name and press OK to proceed. (In my case, I have selected C# and created a project by the name of “EmService”)
4. In the code view, you can see alot of comments with C# code that is already written for you. A sample model HelloWorld is also created by default. Your code will look like:
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
public Service () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string HelloWorld() {
return "Hello World";
}
}
Guess what, your first Web Service is ready!
[WebMethod] attribute denotes that this method will be used by the clients, also this method has to be public in order for a client to use it.
5. To run your web service, simply right click your .asmx file from the “Solution Explorer” and select View in browser.
On the next screen, you will find the HelloWorld method to be listed under Service heading. If you click that, you will find all the SOAP and HTTP code produced.
6. Now, just press the Invoke button to see the result of the method named HelloWorld().