Creating Your First .NET Web Service

Listing 9.1 gets you started with your first Web service.

Listing 9.1. Your First .NET Web Service
					<%@ WebService Language="C#" Class="hks.HelloService"%>
using System;
using System.Web;
using System.Web.Services;

namespace hks
{
      [WebService(Namespace="http://www.hiteshseth.com/webservices")]
   public class HelloService
   {
      [WebMethod(Description="Simple Hello Method")]
      public string sayHello()
      {
         return "Returned from a C# Web Service";
      }
   }
}

Apart from the bold text in the preceding code, everything perhaps looks similar to your first C# program, without the Main() method. Creating a .NET Web service is similar to creating an ASP.NET page, which explains the first line; the directive WebService states that ...

Get Microsoft® .NET Kick Start now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.