Search code examples
delphiiisiis-7isapi

Aborting ISAPI request from client:


App Chain:

  • Running a Delphi ISAPI application under IIS 7.5/Server 2008R2 - 32 bit mode and Classic Mode pipeline.

  • ISAPI app (TISAPIApplication) is built with Delphi XE.

  • Client is a Delphi exe that generates an XML doc containing request content, including unique internal identifier generated on client side for tracking the request content, etc.

  • Client spawns a thread and hits the ISAPI app on webServer, passing in XML doc containing request info;

  • Client thread waits on server reponse and signals client when thread terminates, indicating request has been processed on server.

Problem:

  • User mistakenly sends a request that has potential to run for hours and/or choke up our infrastructure.

  • I want to enable the client app to send a message to server to abort that request (ONLY that request).

Proposed Solution:

My proposed solution is to create a dictionary on the webServer associating my client side unique identifier with a particular handle or ID for the thread that is generated on server side by the ISAPI process to handle the request. This server side ID could subsequently be used to track and abort the request if necessary when client sends request to abort, using the client side identifier.

BUT - I don't know what property/Thread-ID/handle I should be grabbing on the server side, how get to it, and how to use it to abort the request. If I can access the request handler as a Delphi thread all this should be easy enough.

Anyone know how to go about this? I'm quite certain this can be done, but I don't know exactly how to do it. Have looked around in the Delphi XE docs on TWebRequest etc, haven't found much yet.

Again, please note: I need to kill ONLY that particular request and not the whole ISAPI process - I don't want to abort any other pending requests.


Solution

  • From one of my mentors:

    Best way to do this is to spawn a new thread in the ISAPI generated thread and store its reference in a session cache. ISAPI thread waits on this thread while it does your work - you can terminate this thread via your cached reference and ISAPI thread will terminate.

    I implemented this solution and it works very well.