Windows 7 IIS7 require some configurations to get ISAPI DLL works. It is not that straight forward compare to IIS 5.
Install IIS 7
- Go to Control Panel | Programs and Features | Turn on Windows features on or off (require privilege mode).
- Check “Internet Information Services and make sure “ISAPI Extensions” and “ISAPI Filters” is checked as well.
- Click OK button to start installation.
After finish install IIS 7, open your favorite web browser and enter URL http://localhost/ to make sure the IIS is working and running. You might need to check your firewall setting and add exception for port 80 TCP traffic if necessary.
Configure for ISAPI DLL
Add Virtual Directory
First, you may need to add a virtual directory to host your ISAPI DLL:
- Open Internet Information Service Manager (require privilege mode)
- Right click on “Default Web Site” node and click “Add Virtual Directory” of popup menu:
Enter “Alias” and “Physical Path” of the virtual directory:
Enable ISAPI for Virtual Directory
To enable ISAPI for the virtual directory:
- Select the virtual directory node (e.g.: “ISAPI” in this example).
- Double click the “Handler Mappings” icon.
- Click “Edit Feature Permissions…” in Actions panel
- A “Edit Feature Permission” dialog prompt out
- Check “Execute”.
- Click OK button to commit the changes.
Enable Directory Browsing for Virtual Directory
This is optional but is convenient. To enable Directory Browsing for a virtual directory:
- Select the virtual directory node (e.g.: “ISAPI” in this example).
- Double click the “Directory Browsing” icon.
- Click “Enable” in Actions panel.
Edit Anonymous Authentication Credentials
- Select the virtual directory node.
- Double click the “Authentication” icon.
- Click to select “Anonymous Authentication” item.
- Click “Edit…” in Actions panel.
- A dialog will prompt out.
- Checked “Application pool identity” and press OK button to commit changes.
Enable ISAPI modules
- Click on the root node.
- Double click the “ISAPI and CGI Restrictions” icon.
- Click ”Edit Feature Setting …” in Actions panel.
- Check “Allow unspecified ISAPI modules” option. This option allow any ISAPI dll to be executed under IIS. If you don’t use this option, you will need to specify a list of ISAPI DLLs explicitly.
Edit Permission for Virtual Directory
- Select the virtual directory node (e.g.: “ISAPI” in this example).
- Right click on the node and click “Edit Permission” of popup menu.
- A Properties dialog prompt out.
- Switch to “Security” page
- Click Edit button to show Permission dialog.
- Add “IIS_IUSRS” into the permission list.
Enable 32 bits ISAPI DLL on IIS 7 x64
This is only require if you are using IIS7 x64 and would like to run 32 bits ISAPI DLL on the IIS. If your ISAPI DLL and IIS7 is both x86 or both x64, you may skip this step.
- Click “Application Pools” node.
- Click “DefaultAppPool” item
- Click “Advanced Settings …” from Actions panel.
- A “Advanced Settings” dialog prompt out
- Set “Enable 32-bits Applications” to True
- Click OK button to commit changes
If you didn’t enable this options for 32 bits applications, you may encounter the following errors when execute the ISAPI from web browser:
HTTP Error 500.0 - Internal Server Error
The page cannot be displayed because an internal server error has occurred.
HTTP Error 500.0 - Internal Server Error
Module IsapiModule
Notification ExecuteRequestHandler
Handler ISAPI-dll
Error Code 0x800700c1
Requested URL http://localhost:80/isapi/isapi.dll
Physical Path C:\isapi\isapi.dll
Logon Method Anonymous
Logon User Anonymous
You may now deploy your ISAPI DLLs into the virtual directory and start execute the library from web browser.
DataSnap and ISAPI DLL
You may create Delphi DataSnap ISAPP DLL library and deploy on IIS. From time to time, you may encounter compilation error during development or deployment time if you have consume the ISAPI DLL. This is because the ISAPI DLL invoked will cache in the application pool. You are not allow to overwrite the ISAPI DLL while it’s being cached.
To overcome this problem, you need to perform Recycle operation:
- Click “Application Pools” node.
- Right click on “DefaultAppPool” item and click “Recycle…” item.
Deploying as ISAPI DLL is encourage during deployment stage as IIS will cache the ISAPI DLL for performance consideration.
However, the caching might not feasible during development stage as recycling need to be performed while overwrite the ISAPI DLL either by frequent compiling or overwriting. You may consider compile the server modules as CGI application in development time. Each invocation of CGI is a separate OS process and won’t be cache by IIS application pool.
Install CGI on IIS
- Go to Control Panel | Programs and Features | Turn on Windows features on or off (require privilege mode).
- Check “Internet Information Services and make sure “CGI” is checked.
- Click OK button to start installation.
Enable CGI Module
- Click on the root node.
- Double click the “ISAPI and CGI Restrictions” icon.
- Click ”Edit Feature Setting …” in Actions panel.
- Check “Allow unspecified CGI modules” option.
Consume DataSnap Server Methods via URL
The DataSnap server methods are using JSON as data stream via REST protocol. For example, a simple EchoString server method defined as:
type
{$MethodInfo On}
TMyServerMethod = class(TPersistent)
public
function EchoString(Value: string): string;
end;
{$MethodInfo Off}implementation
function TMyServerMethod.EchoString(Value: string): string;
begin
Result := Value;
end;
To access this method compiled in ISAPI DLL via URL, the URL is something like
http://localhost/datasnap/MyISAPI.DLL/datasnap/rest/TMyServerMethod/EchoString/Hello
and the response text will be:
{"result":["Hello"]}
Likewise, a CGI URL is
http://localhost/datasnap/MyCGI.exe/datasnap/rest/TMyServerMethod/EchoString/Hello
Reference:
- DataSnap 2010 HTTP support with an ISAPI dll; Author: Tierney, Jim