The Ex30a Example: An ATL Server Web Site
To see how ATL Server works, let's run through an example. Ex30a is a simple example with a couple of form elements on the page. Here are the steps for creating the example:
Create a new ATL Server project. Choose New from the File menu. Select ATL Server Project. Type Ex30a as the project name. Select the Memory-Backed Session-State Services option from the Session Services section of the Server Options page. Leave all the other options as the defaults.
Examine the code. Notice that there are two subprojects for your ATL Server project: Ex30a and Ex30Isapi. The former project is the application DLL. The latter is the ISAPI DLL that IIS will use. Inside the Ex30a project is a file namedEx30a.srf . This is the SRF file that will be used to process the Web page. Here's the code from the SRF file:
{{// use MSDN's "ATL Server Response File Reference"
to learn about SRF files.}}
{{handler Ex30a.dll/Default}}
This is a test: {{Hello}}
The handler code lives inside Ex30a.dll. The source code for the handler is a class named CEx30aHandler that lives within the fileEx30a.h . Here's the default source code for the handler:
[ request_handler("Default") ]
class CEx30aHandler
{
// additional support goes here...
protected:
// Here is an example of how to use a
// replacement tag with the stencil processor
[ tag_name(name="Hello") ]
HTTP_CODE OnHello(void)
{
m_HttpResponse << "Hello World!";
return HTTP_SUCCESS;
}
}; // class CEx30aHandler
There are no templates appearing in this code because the ATL Server Project Wizard supports attributed programming by default. One of the default options within the wizard is to add deployment support. When this option is selected, Microsoft Visual Studio adds a virtual directory named Ex30a. You can see it by opening up IIS and expanding the Default Web Site node. The list of virtual directories is on the left side—select Ex30a to display the list of application files on the right side. Right-click on the fileEx30a.srf and choose Browse from the shortcut menu. Microsoft Internet Explorer will come up, and you should see a greeting within the browser that says, "This is a test: Hello World!"
Add some form elements to the SRF file. OpenEx30a.srf in Visual Studio and view the code in HTML mode. (There are Design and HTML tabs near the bottom of the editor window.) Add the following boldface code to the file:
<html>
{{// use MSDN's "ATL Server Response File Reference" to learn about
SRF files.}}
<head>
</head>
<body>
<p>{{handler Ex30a.dll/Default}}
</p>
<p>{{Hello}}
</p>
<form action="Ex30a.srf" method="post" id="Form1">
<div id="DIV1" ms_positioning="FlowLayout">
<table height="15" cellSpacing="0" cellPadding="0" width="70"
border="0" ms_1d_layout="TRUE" id="Table1">
<tr>
<td>Name:</td>
</tr>
</table>
</div>
<input id="Name" type="text" name="Name">
<p><input id="Submit" type="submit" value="Button" name="Submit"></p>
</form>
</body>
</html>
This code adds a text box and a submit button to the form. If you switch back to HTML view, you should see them.Rebuild the application (or copy the new SRF file to the new virtual directory) and browse the page again. You should see the elements on the page.
Add a handler to personalize the greeting. Add the following handler to the tag handler class:[ tag_name(name="PersonalGreeting") ]
HTTP_CODE OnPersonalGreeting(void)
{
const CHttpRequestParams& FormFields =
m_HttpRequest.GetFormVars();
CString szName = FormFields.Lookup("Name");
if (szName.Compare(") != 0) {
m_HttpResponse << "You are " << szName;
} else {
m_HttpResponse << "I don't know you.";
}
return HTTP_SUCCESS;
}
This handler checks to see whether the Name text box has been filled in. If so, you'll see a personalized greeting. Otherwise, the browser will display "I don't know you."Add a call to OnPersonalGreeting by adding a PersonalGreeting tag to the SRF file. You can do this in Design mode. Rebuild the application and browse the file. After you type a name in the text box and click the submit button, you should see a personalized greeting, as shown in Figure 30-8.

Figure 30-8: The ATL Server application in action.