
58
|
Chapter 4: Web Services
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
In terms of file structure, web services in ASP.NET are implemented by .asmx
pages. An .asmx page begins with the
@ WebService directive, which contains
attributes instructing the CLR how to run the web service. The .asmx page can
either directly contain the code necessary for the web service to operate or can
contain a C
lass attribute in its @ WebService directive that points to a compiled
class containing the implementation code. In this latter case, the file containing
the source code for the compiled class is called a code-behind file, as introduced
in Chapter 3 and illustrated in Figure 4-2.
Creating a Web Service
There are two different coding techniques with which one can construct a web
service: inline code and code-behind.
Metadata Attributes
Metadata attributes are somewhat similar in concept to attributes on HTML
tags or XML elements. Metadata attributes provide additional information
about assemblies, classes, and class members to the CLR. Attributes tell the
CLR to treat a particular member a certain way or to automatically provide
certain functionality (such as the automatic packaging/unpackaging of SOAP
requests for web services).
Figure 4-2
. How code-behind works
Non-Code-behind
<%@ WebService Language="VB"
Class="Qotd" %>
Imports System.Web.Services ...