The ASP+ Web Service enables web services developers to expose programmatic functionality to web clients without requiring knowledge of HTTP, XML, or custom marshalling in order to do so.
Developers instead create ASP+ Web Services by simply creating NGWS runtime classes that expose one or more public methods marked with the metadata attribute WebMethod. ASP+ then handles these as “web callable” methods at runtime, and automatically route and marshal appropriate arguments in and out of the methods when it receives requests from a client.
For example, the below class provides a (very) simple stock lookup web service:
<%@ WebService Language=”C#” %> using System.Web.Services; public class Investor : WebService { public bool ValidateSymbol(string symbol) { if ((symbol == “MSFT”) || (symbol == “ONTC”)) { return true; } return false; } [ WebMethod ] public double StockLookup(string symbol) { if (ValidateSymbol(symbol) == false) { return –1; } return StockBizObject.LookupLastPrice(symbol); } }
Assuming the above file was saved as Investor.asmx on the http://www.msn.com web site, a user would be able to access the web service as http://www.msn.com/Investor.asmx and would be able to obtain stock information about Microsoft using the StockLookup method accessed via the following url: http://www.msn.com/Investor.asmx/StockLookup?symbol=MSFT.
Important: Note that although the above class exposes two public methods, only one of them, StockLookup, is actually web callable (ValidateSymbol is not marked with the Web Method attribute). ASP+ Web Services has added the extra restriction of requiring public methods to be marked with this metadata to ensure that only those methods that are really intended to be called remotely can actually be invoked (this prevents all of the public methods exposed on the Object base class – like Wait(), HashCode(), ToString(), etc. from being invoked by any random user).