Microsoft has done a great deal to ease the process of building Web Services, especially in Visual Studio .NET. But let’s focus on using just the .NET framework tools here.
First you’ll take a look at a simple Web Service. Then we’ll identify areas where you might have problems. Listings 13.1–13.4 serve as examples of the code that you will need to get started.
using System;
using System.Web.Services;
namespace chap_13_c
{
//Create a class and inherit the WebService functionality
public class TimeService : System.Web.Services.WebService
{
//Constructor
public TimeService()
{
}
//This is required to make the following method SOAP enabled
[WebMethod]
public string GetTime()
{
return DateTime.Now. ToString();
}
}
}
Listing 13.4. Simple Web Service (Visual Basic .NET)
Imports System
Imports System.Web.Services
Public Class TimeService
Inherits System.Web.Services.WebService
<WebMethod()> Public Function GetTime() As String
HelloWorld = Date.Now. ToString()
End Function
End Class
If you look at Listings 13.1–13.4 , you will notice that you have to produce
very little code to create a simple Web Service. Let’s take a look at where you might
run into problems and how to resolve them.