build a simple webservice with delphi 2006 and microsoft server 2003 iis 6.0

Upload: kober1107

Post on 15-Oct-2015

33 views

Category:

Documents


1 download

DESCRIPTION

Build a simple Webservice with Delphi 2006 and Microsoft Server 2003 IIS 6.0

TRANSCRIPT

  • HomeDownloadsPhotosBlog

    Delphi and OS X Blog

    My Experiences w ith W indows,Delphi and Mac OSX Delphi (15) Mac OS X (8) W indows (4) Misc (1) Sharepoint 2010 (1)

    20102009200820072006

    RSS Feed

    Henrik Kehms WebsiteChanging the world, one site at a t ime

    Build a simple Webservice with Delphi 2006 andMicrosoft Server 2003 IIS 6.0

    23 Feb 2007 18:35 In Category: Delphi

    This tutorial describes how to create a simple webservice w ith Delphi 2006, so thatc lient Applicat ions can invoke the WSDL File and use the Webservice. I do notexplain any terms like XML, WSDL, please refer to Google if you need to know whatthis 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 w ith Delphi 2006. The second step is to configurethe ISS 6.0 in your development envoirement, so that the webservice is invokable byclient applicat ions. 1. Build the Webservice DLL with Delphi 2006 (Borland Developer Studio2006) In Delphi 2006 open the Menu Item FileNew..Other

    This brings up the object repository. Please select DelphiProjectsWebServicesSOAP Server Applicat ion

    In the New SOAP Server Applicat ion w indow select ISAPI/NSAPI Dynamic LinkLibrary

    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 w izard aska Create Interface for SOAP module ?

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

    After the w izard has closed the Project is opened in Delphi. In the unitUnit1.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 2006should now look like he follow ing

    If so, the first method can be implemented in the Webservice. To do this, you needto declare the method in the Interface IsampleWebservice In the unit SampleWebserviceIntf.pas. Add a new method called TestFunct ion(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 classTSampleWebservice in the unit SampleWebserviceImpl.pas as well. Since this sampleuses the Format funct ion, SysUtils needs to get added to the uses sect ion. Add a new method called TestFunct ion(I: Integer): String; stdcall; and implement itw ith 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 simpleWebservice 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 createdin the IIS and the Delphi -ISAPI DLL needs to get added as an allowed module tothe configurat ion. Create a new Virtual Directory in the ISS by clicking the popupmenu NewVirtualDirectory

    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 ServiceExtension to the Configurat ion of the IIS. To do this select the Treenode Web Service Extensions and click on the HyperlinkAdd 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 theExtension Sample Webservice in this case. Important is to check the checkbox Setextension status to allowed

    The configurat ion of the Webserver is done so far. You can open theInformationpage of the Delphi-OSAPI DLL by opening http://localhost/samplewebservice/samplewebserviceserver.dll

    W ithhttp://localhost/samplewebservice/samplewebserviceserver.dll/wsdl/ISampleWebserviceYou 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

    Henrik Kehms WebsiteChanging the world, one site at a time

    Build a simple Webservice with Delphi 2006 and Microsoft Server 2003 IIS 6.0Delphi and OS X Blog