Writing
Writing web services is not difficult, on the contrary it's a very easy task, you only need to derive from the System.Web.Services.WebService class, set some public methods with their respective attributes and ready. Lets starting writing our web service:
#File: RemoteWebService.cs
//mcs -r:System,System.Web,System.Web.Services RemoteWebService.cs -t:library
using System;
using System.Web;
using System.Web.Services;
namespace GtkWebservice
{
[WebService (Description="Our first web service")]
public class RemoteWebService : System.Web.Services.WebService
{
[WebMethod (Description="Adds two numbers")]
public int Add (int firstNumber, int secondNumber)
{
return firstNumber + secondNumber;
}
}
}
We need to set the [WebService ()] attribute in the class for setting that class as the web service class, and we need to set the [WebMethod ()] attribute for setting that method as one web service's method, remember to set as public your web service methods, of course if you want to access then by the "outside world".
Page Comments
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.