Distributed Information Systems. From A to Z. - Part II. Building a stand-alone Web service with Indy in Delphi 7

By: Serge Dosyukov

Abstract: This is a 2nd article shows how to build a stand-alone Web service using Indy and Delphi 7

Copyright ) 2003 by Serge Dosyukov

Second article from "Distributed Information Systems. From A to Z" seria.
If you would like to find other articles, there is a list which will lead you:

This article explains how to fit Indy into Delphi 7's Web services (SOAP) support. For more on creating Web services, please refer to Nick Hodges's excellent Borland Community article, Shakespeare on the Web.

One way or another one day you decide to build server which will be your standalone HTTP server and act as Web-service. One of the reason could be to create SOAP based Application server for your n-tier Delphi application.


Delphi Help provide great step-by-step instruction how to create Web service, MIDAS Server (COM, DCOM model), but  there is no information how to create standalone MIDAS n-tier application based on SOAP protocol Almost

Here it was great article by Dave Nottage. This article gave a great idea how to create web-service in Delphi 6 with SOAP support and possibility to publish SOAP Datamodule interfaces, so you can build your MIDAS n-tier system.

Since Borland introduced Delphi 7 and new Indy, we have native support of such functionality.

Native - yes, documented - no.

A recent posts in borland newsgroups and search on google gave us some ideas how to convert existing code from Delphi 6 to a Delphi 7. But  step by step.

The Idea

This is article is a first part out of three. It describes basis.

Second and third parts coming soon, there we will discuss some problems and how to solve it.

Lets start.

We are going to create application which will support next functionality:

  • be a standalone HTTP server
  • use Indy as platform
  • support SOAP publication
  • be able to publish SOAP DataModules so you can make your n-tier server SOAP/HTML based.

HTTP server and SOAP

Everybody knows Indy and use THTTPServer components before. It is easy to drop this component on your application form, but how to make it support SOAP? If you look in "C:\Program Files\Borland\Delphi7\Source\Indy\" folder you can find file IdHTTPWebBrokerBridge.pas. This is what we looking for.

This file is not a part of Indy runtime so you will need to include it in your project as a regular project file. (You also will need IdCompilerDefines.inc to be able compile your project.). So lets copy them into your project folder. For speed issues we might make some modification in a code so lets keep it separate from Indy distribution source.

Here is an implementation of replacement of THTTPServer component extended to support SOAP packets called TIdHTTPWebBrokerBridge. It is class inherited from TCustomHTTPServer and supported basic request binding.

Because it is not a component available on your palette, you will need to create it as regular object at runtime in your code.

You can use it exactly the same way you use regular THTTPServer except few things you need to do in addition to make it works with SOAP.

But before we do this lets prepare some code to use.

WebBroker and Indy

If you ever create Web Service before you know we will use WebBroker. Delphi 7 as well as Delphi 6 uses WebBroker architecture to support SOAP.

So you need to create TWebModule and put three components on it: THTTPSoapDispatcher, THTTPSoapPascalInvoker, TWSDLHTMLPublish - all available on WebServices tab in component palette. Link SOAPDispatcher with SOAPPascalInvoker and form is ready. So finally you will have something like this (uWebModule.pas unit):

You do not need to modify or implement any custom code for this form, so lets live it as is.

WebModule and Indy

And there is next part of the code you need to put in your HTTPServer implementation.

As you can see TIdHTTPWebBrokerBridge has a method called RegisterWebModuleClass which allow you to register your WebModule and make it available for server.

So lets just call fServer.RegisterWebModuleClass(TwmSOAPIndy) after we created a server object fServer.

Note: In standard implementation of TIdHTTPWebBrokerBridge TwmSOAPIndy object will be created each time when request came in. Apparently there is no need for it, so in my version I modified a class to have creation persistent while Server object exists. Check class implementation for detail.

"Ready or not, there I am"

"So what next?", will you ask.

Almost nothing, server is ready.

You need only add your TSoapDataModule and business logic implementation and server will be ready completely.

Service? Easy.

Because in our example application is just regular application you can easily convert it to a service in regular manner.

No special work should be done.>br> Couple things you have to remember:

  • If your DB connections uses trusted connection you have to remember what service has special account it used to login to a database server.
  • If you use file storage on your local drive, you need to specify full path. Service is special type of program, it does not know anything about current folder. You can use ExtractFilePath(Forms.Application.EXEName) to get current folder in such situation or use a registry to store RootPath for your application.

You can use user account by changing what account service uses to start.


Here is an example application which shows a result of our work.

It is a standalone server with SOAP support. It has one SOAP interface and CDS available for client application via SOAP/MIDAS interface.

On a server side we show count of database operations performed on server.

If you click Hello button you will see a result of call remote interface.


There are some link which I found helpful...
Creating multi-tier information systems using MIDAS - old article, but it provides basic information for understanding how N-tier application could be build using MIDAS in Delphi 5.
WebSnap and Web Services hand-in-hand
Dr. Bob!!! Great Bob Swart!!! Bob Swart's Delphi Artikelen MIDAS 2 N-Tier Ontwikkelingen
WebSnap Custom Adapter Source Generator Getting started with WebSnap in Delphi 6 Enterprise - by John Kaster

Contact author

Questions, comments, suggestions, please contact me using this e-mail .
Please replace _at_ with @ and -dot- with "."
More information about author and links to other articles available from http://www.dragonsoft.spb.ru.

Server Response from: ETNASC04