WebService Directive

You can see the first difference between a web service and a web page in the web service file listed in Example 15-2. A normal .aspx file will have a Page directive as its first line, but a web service has a WebService directive as reproduced here:

    <%@ WebService Language="C#" CodeBehind="~/App_Code/Service.cs"
        Class="Service" %>

The WebService directive is required of all web services. Like all directives, it has the following syntax:

    <%@ DirectiveName attribute="value" [attribute="value"...]%>

You can have multiple attribute/value pairs. The order of the attribute/value pairs does not matter.

Language

The WebService directive’s Language attribute specifies the language used in the web service. Legal values include C#, VB, and JS for C#, VB2005, and Jscript.NET, respectively. The value is not case-sensitive. The Language attribute is not required. If it is missing, the compiler will deduce the language in use from the extension of the class file.

Class

The WebService directive’s Class attribute specifies the name of the class implementing the web service. The Class attribute is required. The class specified can reside either in a separate code-behind file, or in-line in a script block in the .asmx file.

If the web service is developed in VS2005, the code-behind file containing the class will be located in a subdirectory under the application root (where the .asmx file resides) called App_Code. Any code files in a subdirectory with this name will automatically ...

Get Programming ASP.NET, 3rd Edition 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.