DataSnap 2010 HTTP support with an ISAPI dll
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.
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”.
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.
Friday, 21 August 2009
This example, which demonstrate RDM in DataSnap 2009 server, may help you answer this question: http://cc.embarcadero.com/Item/26057. DataSnap 2009 only supported TCP/IP. HTTP would be easy to add with Delphi 2010.
Tuesday, 15 March 2011
1. I can't seem to find "ISAPI & CGI Restrictions" icon among my features in the IIS Manager.
Am I missing anything? should I add it somehow?
2. what's a dataExplorer? should I have it on my Windows 7? or is it a Windows Server application?
3. where do I write "[c:/]net stop w3svc" and "[c:/]net start w3svc"???
4. Any idea about a free/efficient Database System that I can use with my DataSnap application?
Tuesday, 27 December 2011
When I use C++ Builder XE following your article,it works correct in win7(32bit) ans IIS 7.0(32bit),and deployed in a machine.
But when I deploy the same dll in Windows 2008(64bit) and IIS 7.0(without installed XE2),when I click the dll,it will show file download dialog.
Can you help me?
Tuesday, 27 December 2011
IIS doesn't recognize this as an ISAPI dll. Here is one way to enable ISAPI support IIS 7:
- Start IIS Manager
- Select the machine in the tree
- Select the ISAPI and CGI restrictions icon
- Choose the Open Feature... command
- Choose Edit Feature Settings...
- Check allow unspecified ISAPI modules
Wednesday, 28 December 2011
I reinstalled all components (such as asp) of IIS 7 in Windows 2008,and it works correct.
When I browse the link ,it can show the response,but when I connected with XE2 Client,it show the error:
Borland.Data.TDBXError:405 Method Not Allowed.
The link is:
Please login first in order for you to submit comments
- Page :
Jim, we have existing datasnap servers (Delphi 2007) using a main RDM and child RDM's. Will we be able to rewrite these to use the new Datasnap features in Delphi 2010?