Friday, March 30, 2012

How to create a Webservice in Visual studio 2010



Click on File->New ->project
Select the Asp.NET Empty Web Application and click so it will be creating a new Web application
In that you will be able to add the web service

In solution explore Right Click on the Project and select Add New Item




In  the New window opened you will be able to find Web Service  
Select that and Click Ok.                                           


So your new web Service has been created

In the code view, you can see lot of comments and C# code already written for you. You will also see that at the bottom, there is a method HelloWorld which is written for you by default, so you can test your service and of course say hello to the world.below is the code which is generated by default...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace WebApplication1
{
    ///

    /// Summary description for WebService1
    ///

    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
    // [System.Web.Script.Services.ScriptService]
    public class WebService1 : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }
    }
}

No comments:

Post a Comment