With DataSnap in Delphi 2010, you can develop DataSnap clients and server that communicate over HTTP. One way to implement the server is as an ISAPI dll. I’ve been given permission to show this feature pre-release. See http://www.embarcadero.com/rad-studio-2010 for for more information about the upcoming release.
Click these links to skip ahead Configure IIS, Connect with Data Explorer, Ancestors and DataModules, ISAPI debugging
In the File/New… dialog, double click “DataSnap WebBroker Application”

Check “ISAPI/NSAPI Dynamic link Library”, “Add Server Methods Class” and “Include sample methods”.
Select TPersistent as the ancestor class for the server methods. I will say more about the ancestor choices later in this post.

Click OK to create a new project.

The new project has two units. ServerMethodsUnit implements the server methods for this DataSnap server. There is a single server method called EchoString with a string parameter (see my previous posts to learn more about server method parameter types).

The WebModule contains the components that make this ISAPI dll function as a DataSnap 2010 HTTP server.

DSServer1 and DSServerClass are the same components used in stand alone TCP/IP DataSnap servers. DSHTTPWebDispatcher is new to DataSnap 2010. It is responsible for managing ISAPI/WebBroker HTTP requests and responses on behalf of the DataSnap Server.
Both DSHTTPWebDispatcher1 and DSServerClass1 components have their “Server” property set to “DSServer1”. The DSServerClass1 component calls an event handler to get the type of the server methods class:

The wizard has generated a complete ISAPI application so no changes are required to the project source code, however I do need to configure IIS.
Configure IIS
Here is how I configure IIS 6.0 on my Vista x32 system.
If you haven’t enabled IIS on your system then use “Programs and features”/”Turn Windows features on or off” to install.
Start Internet Information Services (IIS) Manager.
Expand Connections nodes, right click on “Default Web Site”, choose “Add Virtual Directory”.
Enter an alias of “DSProject” an a physical path of "c:\DSProject".

ISAPI must be enabled for this virtual directory. Select the “DSProjects” Connections node. Double click the “Handler Mappings” icon. Click Actions/“Edit Handler Permissions…”. Check “Execute”.
Directory browsing is convenient but not required. Enable it for this example. Select “DSProjects” Connections node. Double click the “Directory Browsing” icon. Click Actions/”Enable”.
Almost done configuring IIS. Click on the root Connection node. Double click the “ISAPI and CGI Restrictions” icon. Click Actions/”Edit Feature Setting…”. I have “Allow unspecified ISAPI modules” checked. If you don’t check this then you will need to add to the list of ISAPI dlls recognized by IIS, after you have built your project.
Now go back to Delphi 2010 and set the output directory to the virtual directory physical path c:\DSProject.

Build the project.
Browse to http://localhost/DSProject and, if you have enabled directory browsing, you should see the ISAPI dll. Click it. You should see a page like this:

The following a wizard generated line of code provide the default content:
At this point it looks like our ISAPI dll is properly configured. Now I can use the Data Explorer to test connectivity.
Connect with Data Explorer
I prefer to use the stand alone DataExplore.exe when testing connections rather than the RAD studio Data Explorer view, just in case there is a connection problem that causes the client to become unresponsive.
Start DataExplorer.exe. Right click the DataSnap node, choose add connection. Enter “NewConnection”. Click OK.

Expand the DataSnap node, right click “New Connection” and select “Modify Connection”.
Set Protocol to “http”, Host to “localhost”, Port to “80” and Path to “DsProject/Project1.dll”.
Click “Test Connection”. Click OK. Click OK.

Expand the NewConnection/Procedures node to see that EchoString is a server method.

To test, right click on the “EchoString” node and choose "View Parameters". Select the "Value" parameter and enter some text for the "Value" property. Right click and choose "Execute" (or click the the image button in the upper left of the view parameters window).

At this point I’ve created a server, configured it to run under IIS, and connected to it with DataExplorer. The new DataSnap 2010 HTTP client features will need to be covered in another post.
I have two additional topics to cover. First is this ancestor issue I mentioned near the beginning of this post. Finally, I will add a few words about debugging.
Ancestors and DataModules
This example used TPersistent as the ancestor of our server method class. The other choices, in the wizard, are TDataModule and TDSServerModule. Use TDataModule when you want to use components in your server methods. Use TDSServerModule when you want the equivalent of TRemoteDataModule.
When using TDataModule or TDSServerModule, there is an important requirement that only affects WebBroker applications. Be sure that the there is only one module created during startup. Use Project/View Source… to see this code. The only module created here should be the WebModule.
The project source should look like this:

Something like this will result in an exception with the message “Only one data module per application”.

ISAPI Debugging
In case your ISAPI dll isn’t working properly because of this or other issues, here is how I configure my project for debugging.
In project options, set Host application to the location of w3wp.exe and the Parameters to “-debug”.

You will need to stop IIS before debugging. Use the IIS manager or [c:/]net stop w3svc.
When you run the application, you should see a prompt like this:
When you stop debugging, w3wp.exe will be shut down. When you are done working on your project, restore IIS with [c:/]net start w3svc.
Share This | Email this page to a friend
Tagged DataSnap, HTTP, ServerMethods, WebBroker