DotNet Tutorials

V4 Dot Net Tutorials

Server Intellect Cloud Hosting

 Simple Web Service

How to Create a Simple Web Service in ASP.NET
Introduction
In This Tutorial We will be creating a Web Service.  In the next tutorial we will learn how to "Consume" the Web Service that we create here.

Step 1. Create a Web Service
We need to create a web service by right clicking on the project and selecting Add then Selecting New Item.  Select Web Service and name it "MyService.asmx".  now go into the Web Service code and paste the following code in there. Note in some versions of Visual Studio this function might already be there, if so move on.

Try Server Intellect for Windows Server Hosting. Quality and Quantity!

using System.Data.SqlClient;
using System.Configuration;
using System.Web.Configuration;
using System.Net;

namespace webService

{

    /// 

    /// Summary description for MyService

    /// 

    [WebService(Namespace = "http://tempuri.org/")]

    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

    [System.ComponentModel.ToolboxItem(false)]


    public class MyService : System.Web.Services.WebService

    {



        [WebMethod]

        public string HelloWorld()

        {

            return "Hello World";

        }
}
}
	
    
Step 2. Invoking the Function
 Now that we have created a simple web service we need to test it out and make sure the function works.  Go ahead and run this page then select Hello world and then press the Invoke button. You should see the words Hello World on the screen.

I just signed up at Server Intellect and couldn't be more pleased with my Windows Server! Check it out and see for yourself.

Conclusion
So we have no created a simple web service and in the next tutorial we will learn how to reference this service and Consume it so that we can call it's functions.
Download Project Source - Enter your Email to be emailed a link to download the Full Source Project used in this Tutorial!



100% SPAM FREE! We will never sell or rent your email address!