Genivia Home Documentation
The ISAPI extension

updated Wed Jul 13 2016
 
The ISAPI extension

Table of Contents

By Christian Aberger, Robert van Engelen, and Chris Moutsos.

Overview

SOAP/XML and REST Web services can be easily created and deployed as gSOAP standalone services or installed as (Fast)CGI applications. In addition, the mod_gsoap Internet Server Application Programming Interface (ISAPI) extension offers the ability to run gSOAP services directly inside the Microsoft Internet Information Server (IIS). This is achieved through an ISAPI extension DLL. The ISAPI extension supports the deployment of multiple gSOAP services that can run together with the usual services on IIS. This approach offers a production-quality Web services deployment scenario.

The mod_gsoap ISAPI extension is designed to keep things simple so that existing gSOAP services can be recompiled for IIS deployment without modification of the source code. The mod_gsoap.dll DLL (dynamic link library) implements the ISAPI extension that uses the query string of the request URL to determine which gSOAP back-end service to run. It will select the appropriate service DLL to load the service dynamically, if not already present. Therefore, to add more services, simply create new DLLs for these services. IIS need not be restarted to deploy them.

Installation

To build and install the mod_gsoap.dll ISAPI extension for gSOAP:

In gsoap\mod_gsoap\gsoap_win\isapi\, there are two directories called vs2006 and vs2010. Choose the appropriate directory and installation instructions based on your version of Visual Studio.

Visual Studio 2010 Service Pack 1 (version 10.0.40219.1) or later (IDE):

Visual Studio 2010 Service Pack 1 (version 10.0.40219.1) or later (Developer Command Prompt for VS):

Visual Studio C++ 6.0:

Deploying services with ISAPI

After building mod_gsoap.dll we are ready to deploy gSOAP services with the ISAPI extension.

The gSOAP package contains a calculator example to demonstrate the ISAPI extension. You will find this example in the gSOAP package under gsoap\mod_gsoap\gsoap_win\isapi\vs20##\samples\calc. We will use this example to walk you through the creation and deployment of an ISAPI service, so make sure to build it (see Intallation section).

To test the calculator IIS service with a simple client, do the following:

We recommend to test services first as standalone gSOAP services to ensure that the service logic is correct. If the service logic is correct but the service DLL does not produce a response, then please see the next section. Otherwise, read on.

A Makefile is included that contains commands to start and stop debugging of IIS and for cleaning the directory. The advanced user can compile everything with just one command. Be sure that msdev.exe (VS2006 only) and nmake.exe are on your PATH. Then enter the command nmake from a DOS command window and presto!

To develop your own service DLL in Visual Studio, select File|New and create a new empty Dynamic Link Library project. Copy stdsoap2.def from the mod_gsoap\gsoap_win\isapi\vs20##\samples\calc directory to your project directory and add it to the project. This will ensure that the required functions are exported and visible to mod_gsoap, such as soap_serve that invokes service operations (this function is auto-generated by soapcpp2.exe and defined in soapServer.cpp).

In addition, two C functions should be defined by your service code, namely int mod_gsoap_init(void) and int mod_gsoap_terminate(void):

extern "C" {
int mod_gsoap_init(void) {
// TODO: add your initialization code here
return SOAP_OK;
}
int mod_gsoap_terminate(void) {
// TODO: add your termination code here
return SOAP_OK;
}

The mod_gsoap_init function is called by mod_gsoap when the DLL was successfully loaded and before processing begins. The mod_gsoap_terminate function is called when the DLL is unloaded. These functions should return SOAP_OK on success. You can use these initialization and termination hooks as you see fit.

Multiple ISAPI services can run together with all other Internet services on your machine on port 80 (or another port, as configured in IIS). The request your client must submit is a URL with a query string, such as was illustrated above with http://127.0.0.1/gsoap/mod_gsoap.dll?gsoap/calc.

The requested URL is evaluated by IIS and the query string (the part after the ?) is used to dispatch the service request to the calc.dll service.

Note that instead of 127.0.0.1 (which is the localhost), clients on the network should use the full domain name of the machine.

For security reasons only DLLs stored in the same directory as mod_gsoap.dll can be used. If you want to do specialized initializations in your DLL then you may want to add and export a DllMain function, which will be called when the IIS process attaches to your DLL and before it detaches it. Do not rely on the Thread attach/detach callback: in my experience IIS does not always call DllMain in your DLL if these threads were already in the thread pool before your DLL was loaded. Use thread local storage instead.

Troubleshooting

If the client receives an error from the ISAPI service, such as for example:

SOAP FAULT: SOAP-ENV:Client
"End of file or no input"
Detail: http://localhost/gsoap/mod_gsoap.dll?gsoap/calc

Then we recommend the following steps:

If you want to debug a DLL, you must set the DLL to run in-proccess. Right-click on the gsoap virtual root in internet service manager and set the Application Protection to Low (IIS Process). Remove the Enable Session State and buffering and Parent Paths. Don't forget to allow the IISAdmin and WWW Service to interact with the desktop.

To enable debugging of services and/or clients:

Note: for Debugging with Win2000 there are two .reg files in the Div directory, that switch debugging of IIS on and off (see Q273639 and related), and a start and stop command in the Makefile to start and stop IIS debugging. Make sure that the path to msdev is in the System environment variables (PATH) of the system account (not only of your own user account, this is not seen by IISAdmin).

Creating the virtual root

If you have problems creating the virtual root then these instructions should help.

For testing it might be best to enable the Browse permission and then browse to http://localhost/gsoap.

License

The ISAPI extension for gSOAP is released under the gSOAP open source public license (compatible with commercial licensing) and GPLv2.

Further reading

What is an ISAPI Extension?

ISAPI Extensions as explained by Microsoft