Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Home

Downloads
Photos
Blog
Delphi and OS X Blog
My Experiences with Windows,
Delphi and Mac OSX
Delphi (15)
Mac OS X (8)
Windows (4)
Misc (1)
Sharepoint 2010 (1)
2010
2009
2008
2007
2006
RSS Feed
Henrik Kehms Website
Changing the world, one site at a time
Build a simple Webservice with Delphi 2006 and
Microsoft Server 2003 IIS 6.0
23 Feb 2007 18:35 In Category: Delphi
This tutorial describes how to create a simple webservice with Delphi 2006, so that
client Applications can invoke the WSDL File and use the Webservice. I do not
explain any terms like XML, WSDL, please refer to Google if you need to know what
this means. Also I do not describe any security relevant configuratuions in the IIS,
the Setup is an development envoirement.

The first step is to build the DLL with Delphi 2006. The second step is to configure
the ISS 6.0 in your development envoirement, so that the webservice is invokable by
client applications.

1. Build the Webservice DLL with Delphi 2006 (Borland Developer Studio
2006)

In Delphi 2006 open the Menu Item FileNew..Other

This brings up the object repository. Please select Delphi
ProjectsWebServicesSOAP Server Application

In the New SOAP Server Application window select ISAPI/NSAPI Dynamic Link
Library
Build a simple Webservice with Delphi 2006 and Microsoft Server 2003 IIS 6.0 | Delphi | Henrik Kehms Website 5/18/2014
http://www.kehm.de/henrik/blog/files/e425def97295c6eb536a0d568d169b3b-15.html 1 / 7

Please select Yes when the wizard aska Create Interface for SOAP module ?

In the Window Add new Webservice supply the desired name for the new
Webservice SampleWebservice in
this case. Also check Generate comments.

After the wizard has closed the Project is opened in Delphi. In the unit
Unit1.pas the class TWebModule1 is declared. Use the
Refactor function to rename the class to TsampleWebModule.

type
TSampleWebmodule = class(TWebModule)
HTTPSoapDispatcher1: THTTPSoapDispatcher;
HTTPSoapPascalInvoker1: THTTPSoapPascalInvoker;
WSDLHTMLPublish1: TWSDLHTMLPublish;
procedure WebModule1DefaultHandlerAction(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled:
Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;


Save Unit1.pas as SampleWebservice.pas
Build a simple Webservice with Delphi 2006 and Microsoft Server 2003 IIS 6.0 | Delphi | Henrik Kehms Website 5/18/2014
http://www.kehm.de/henrik/blog/files/e425def97295c6eb536a0d568d169b3b-15.html 2 / 7

Save the Project as SampleWebserviceServer.bdsproj

The setup of the Webservice Project is done so far, the Project in Delphi 2006
should now look like he following

If so, the first method can be implemented in the Webservice. To do this, you need
to declare the method in the Interface IsampleWebservice
In the unit SampleWebserviceIntf.pas.

Add a new method called TestFunction(I: Integer): String; stdcall;

{ Invokable interfaces must derive from IInvokable }
ISampleWebservice = interface(IInvokable)
['{10D6113D-7306-479F-882D-A276BCF43936}']
{ Methods of Invokable interface must not use the default }
{ calling convention; stdcall is recommended }
Build a simple Webservice with Delphi 2006 and Microsoft Server 2003 IIS 6.0 | Delphi | Henrik Kehms Website 5/18/2014
http://www.kehm.de/henrik/blog/files/e425def97295c6eb536a0d568d169b3b-15.html 3 / 7
function TestFunction(i: Integer): String; stdcall;
end;

Now the new interface method needs to get implemented in the class
TSampleWebservice in the unit SampleWebserviceImpl.pas as well. Since this sample
uses the Format function, SysUtils needs to get added to the uses section.

Add a new method called TestFunction(I: Integer): String; stdcall; and implement it
with some sample code

TSampleWebservice = class(TInvokableClass, ISampleWebservice)
public
function TestFunction(i: Integer): String; stdcall;
end;
[]
function TSampleWebservice.TestFunction(i: Integer): String;
begin
Result := Format('You called the Testmethod with %d', [i]);
end;

Press Build to build the ISAPI DLL. This is all, that needs to be done for this simple
Webservice in Delphi, the next step is to configure the IIS.

2. Configure the Internet Information Server 6.0

In order to use the Simple Webservice a new Virtual Directory needs to get created
in the IIS and the Delphi -ISAPI DLL needs to get added as an allowed module to
the configuration.

Create a new Virtual Directory in the ISS by clicking the popupmenu NewVirtual
Directory


Supply a name for the Virtual Directory

And select the Path where the output path of the Delphi-DLL
Build a simple Webservice with Delphi 2006 and Microsoft Server 2003 IIS 6.0 | Delphi | Henrik Kehms Website 5/18/2014
http://www.kehm.de/henrik/blog/files/e425def97295c6eb536a0d568d169b3b-15.html 4 / 7

In the Virtual Directory Access Permissions select Read and Execute

The new Virtual Directory should appear now in the Treeview.

Now the Delphi-ISAPI DLL needs to get added as an allowed Web Service
Extension to the Configuration of the IIS.
To do this select the Treenode Web Service Extensions and click on the Hyperlink
Add new Web service extension
Build a simple Webservice with Delphi 2006 and Microsoft Server 2003 IIS 6.0 | Delphi | Henrik Kehms Website 5/18/2014
http://www.kehm.de/henrik/blog/files/e425def97295c6eb536a0d568d169b3b-15.html 5 / 7

Select the Delphi-ISAPI DLL by clicking the Add Button and supply a name for the
Extension Sample Webservice in this case. Important is to check the checkbox Set
extension status to allowed
The configuration of the Webserver is done so far. You can open the
Informationpage of the Delphi-OSAPI DLL by opening
http://localhost/samplewebservice/samplewebserviceserver.dll

With
http://localhost/samplewebservice/samplewebserviceserver.dll/wsdl/ISampleWebservice
You can import the Webservice e.g. in Visual Studio or in Delphi 2006
Build a simple Webservice with Delphi 2006 and Microsoft Server 2003 IIS 6.0 | Delphi | Henrik Kehms Website 5/18/2014
http://www.kehm.de/henrik/blog/files/e425def97295c6eb536a0d568d169b3b-15.html 6 / 7
Home > Blog >
2010 Henrik Kehm Kontakt
Build a simple Webservice with Delphi 2006 and Microsoft Server 2003 IIS 6.0 | Delphi | Henrik Kehms Website 5/18/2014
http://www.kehm.de/henrik/blog/files/e425def97295c6eb536a0d568d169b3b-15.html 7 / 7

You might also like