ASMX Pages

ASP.NET was designed to provide a web service infrastructure and programming model that allows developers to create, deploy, and maintain web services without the need to understand SOAP, WSDL, and so on. ASP.NET accomplished this goal through the introduction of XML web services, which is built on top of ASP.NET and the .NET Framework. Developers can easily create web services by creating files with .asmx extension(for example, Customers.asmx) and deploying them as part of a web application. Like ASPX files, ASMX files are intercepted by an ISAPI extensio(aspnet_isapi.dll) and processed in a separate ASP.NET worker process. The ASMX file must either reference a .NET class or contain the class itself. The only mandatory entry in the ASMX file is the WebService directive, which specifies the class and the language. Listing B-1 shows an example of the directive where theclass being used is Customers.

Example. WebService Directive in an .asmx File
<%WebService Language="c#" Class="Customers" Codebehind="Customers.cs" %>

You can set the default XML namespace for the web service by applying the WebService attribute to the class implementing the web service; in addition, you should change the default namespace from http://tempuri.org to something unique. Methods of this class do not have the ability to process web service requests. To make the methods available through a web service, you need to apply a WebMethod attribute to the public method. Once these methods are decorated with the WebMethod attribute, they are called web methods and can communicate over the wire. This class can also optionally derive from the WebService class, which allows the web service to gain access to the common ASP.NET objects such as User, Context, Session, Application, and so on. Listing B-2 shows a sample containing two public methods; one is a web service, and the other is not because we have the WebMethod attribute on only one method.

Example. Defining Web Service Methods
<%@ WebService Language="C#" Class="Util" %>
using System.Web.Services;
using System;
[WebService(Namespace="http://www.quickreturn.com/")]
public class CalculateReturn: WebService
{
    [WebMethod]
    public int Multiply(int a, int b)
    {
        return a * b;
    }
    public int Add(int a, int b)
    {
        return a + b;
    }
}

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset