ARTICLE

How to create Web Services in ASP.NET

Posted by Gohil Jayendrasinh Articles | Web Services in C# November 19, 2010
In this article we will see how to create Web Services in ASP.NET.
Reader Level:
Download Files:
 

1.gif

Your web services code.

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

namespace MyServices
{
    /// <summary>
    /// Summary description for MyServicesExample
    /// </summary>
    [WebService(Namespace = "http://MyServices.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 MyServicesExample : System.Web.Services.WebService
    {
        [WebMethod]
        public string GetMyname()
        {
            return "Hi ! My Name is Gohil Jayendra.";
        }
    }
}

Your web page code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NameInfo;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void btnname_Click(object sender, EventArgs e)
    {
        NameInfo.MyServicesExample example = new MyServicesExample();
        lblname.Text = example.GetMyname();      
    }
}

Login to add your contents and source code to this article
post comment
     

Can you please explain step by step, how to create Web service and how to the call the service in web page... -Thanks and regards, Selva selvamsc@gmail.com

Posted by Selva ganapathy Jun 24, 2011
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
Join a Chapter
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.