Delphi Clinic C++Builder Gate Training & Consultancy Delphi Notes Weblog Dr.Bob's Webshop
Bob Swart (aka Dr.Bob) - Medical Officer TDMWeb Kylix Developer's Guide
 Kylix 2 BizSnap - XML, SOAP & WebServices (6 of 6)
See Also: Kylix Papers and Columns

I have been working on an BizSnap chapter for the Kylix Developer's Guide - adding more coverage of Kylix 2 to this book. The BizSnap chapter will be published on my website (in six weekly parts), covering XML Document Programming and Web Services support.


BizSnap is the name given by Borland to describe the feature set of Kylix 2 Enterprise that covers XML document programming as well as Web Services (using SOAP). In this chapter, we will first cover XML document programming using the TXMLDocument component. This will be enhanced using XML Data Binding and even further using the XML Mapping Tool.
We then move on to Web Services, and after a short introduction to SOAP, we'll implement our first Web Service in Kylix 2, followed by the usage (consuming) of Web Services written in Kylix or other development environments. Finally, we show the powerful combination of BizSnap with DataSnap to produce distributed applications (even cross-platform, considering that Delphi 6 also supports this on Windows).

6. Web Services and DataSnap
DataSnap is the name for the technology that enables distributed applications using Kylix (or Delphi for that matter). Having multiple tiers in a distributed application requires the different tiers to connect to each other using a communication protocol that they can both understand. For Kylix (which runs on Linux, and produces applications for Linux), the communication is based on SOAP, which means you have a SOAP (remote) Data Module and TDataSetProvider component on the server side, and a TSOAPConnection component on the client side. In the following subsections, I will show the steps to build a Soap Server and Client using Kylix 2 Enterprise.

Kylix 2 Enterprise Soap Server
Let's start by building a SOAP DataSnap CGI executable Server in Kylix 2 Enterprise, which consists of the following steps:

  1. Start Kylix 2 Enterprise, and close the default project (if any).
  2. Choose File | New, and go to the Web Services tab of the Object Repository.
  3. Double-click on the SOAP Server Application icon, which opens the New Soap Server Application dialog.

    Figure 20: New SOAP Server Application

  4. Select CGI executable and click on the OK button. A new Soap Server Application has now been generated for you.
  5. The Soap Web module contains three automatically generated components: THTTPSoapDispatcher, THTTPSoapPascalInvoker, and TWSDLHTMLPublish.

    Figure 21: Soap Server Web module

  6. Save the Soap Web module in file SWebMod.pas and the project in file SoapServer42.dpr.
  7. Choose File | New, and go back to the Web Services tab of the Object Repository.
  8. This time, double-click on the SOAP Data Module icon, which results in the Soap Data Module Wizard.

    Figure 22: New Soap Data Module Wizard

  9. Enter SoapDataMod42 as the Class Name, and click on the OK button. A new Soap Data Module has now been generated for you.
  10. Save this new unit with the Soap Data Module as SDataMod.pas.
  11. Drop a TClientDataSet component on the Soap Data Module, and set its Name property to cdsBiolife. Set its FileName property to biolife.xml (from the kylix2/demos/db/data subdirectory)
  12. Drop a TDataSetProvider component on the Soap Data Module, and set its Name property to dspBiolife and its DataSet property to cdsBiolife.
  13. If you want to be able to update the data (from your remote client), then you have to make sure that the ResolveToDataSet property of the TDataSetProvider component is set to True.

    Figure 23: Soap Server Data module

  14. Compile and deploy your SoapServer42 application in the cgi-bin or scripts directory of your Web server. Make sure to remember the URL (like http://server/...) or IP address of your SOAP server machine; you need it when building the SOAP Client.
  15. You can test the output of a browser using the /wsdl switch. If you see the interfaces IWSDLPublish and IAppServer as well as ISoapServer, you're set.

    Figure 24: WebService listing in Netscape browser

Kylix 2 Enterprise Soap Client
Now that you have a SOAP DataSnap CGI executable Server written in Kylix 2 Enterprise, you can start writing the Soap DataSnap Client written in Kylix 2 Enterprise, using the following steps:

  1. Start Kylix 2 Enterprise, and start the project type that you want (anything works).
  2. Save Unit1 as ClientForm.pas, and the project in file SoapClient.dpr.
  3. Drop a TSoapConnection component from the Web Services tab of Kylix 2 Enterprise.
  4. Set the URL property of the SoapConnection component to http://server/cgi-bin/ (where server is the name or IP-address of your SOAP server machine) followed by the name of the Soap Server application (SoapServer42), followed by /soap, and the interface name of your Soap Data Module (/ISoapDataMod42) resulting in http://server/cgi-bin/SoapServer42/soap/ISoapDataMod42.
    Note: instead of ISoapDataMod42, you can also use the more generic IAppServer, but you need to explicitly add either of them after the /soap part of the URL property.
  5. Drop a TClientDataSet component, and set its RemoteServer property to the SoapConnection component.
  6. Now, open up the ProviderName property, which will list dspBiolife (as exported from the Soap Data Module).
  7. Drop a TDataSource component, and set its DataSet property to the ClientDataSet component.
  8. Drop a TDBGrid component, and set its DataSource property to the TDataSource component.
  9. Drop a TDBNavigator component, and set its DataSource property to the TDataSource component too.
  10. Drop a TDBImage component, set its DataSource property to the TDataSource component, and its DataField property to 'Graphic'. Note that it may take a few seconds for the combo box of the DataField property to drop-down, due to the fact that the ClientDataSet has to request the metadata (to obtain the fieldnames) from the SOAP Server.
  11. Finally, set the Active property of the ClientDataSet component to True to get live data at design-time (see Figure 25)

    Figure 25: SOAP client connecting to SOAP Server WebService

Again, if you want to make modifications to the client application and send these back to the server, you need to call the ApplyUpdates methods (see the DataSnap chapter for more details on this).
A final word on performance issues. Please note that it may take a while before you get a response when you first click on any of the two buttons. The delay is caused by the fact that a SOAP request has to be put in a SOAP envelope and sent over the Internet to the Web service (using HTTP). At the server machine, the Web server CGI executable has to be started, and then it must unpack the SOAP envelope, dispatch the SOAP request, execute the Object Pascal method, pack the result back in a SOAP envelope again, send it back to the Web service consumer (again over the Internet using HTTP) and then exit the Web service CGI executable again. A more efficient approach for real-world Web services will certainly be to deploy Apache DSO modules (see chapter 19 for more details on writing Apache DSOs with Kylix).

Summary
SOAP is still work in progress. And although it's nice for Kylix 2 to talk to Delphi 6 and others, in the end many more environments on more platforms should be able to talk with each other using Web Services and SOAP. And to check the interoperability of all these SOAP implementations, a special SOAP interoperability testing has been set up.
It should be clear that SOAP, Web Services, and their implementation in Borland development tools isn't finished, but has hardly started. You'll see lots more SOAP in the future. In the meantime, feel free to check out my Web site, Dr.Bob's SOAP Bubbles, at http://www.drbob42.com/SOAP.


This webpage © 2002-2009 by Bob Swart (aka Dr.Bob - www.drbob42.com). All Rights Reserved