RAD Studio for Microsoft .NET |  |

Porting Web Service Clients
Changes and Additions to Your Applications | Implementation Notes | See Also
Collapse All

RAD Studio web services use the .NET Framework as the services layer. As a consequence, any existing Delphi 7 or earlier web service client applications need to be modified to use the .NET Framework.

This topic includes:

- Changes and Additions to Your Applications
- Implementation Notes

Changes and Additions to Your Applications

Make the following changes and additions to your applications:

- Remove RIO components from your applications. They will no longer work in the .NET Framework. Before deleting any components, save property information for the components, such as URLs.
- Remove Delphi 7 SOAP units from the uses clause and remove the uses reference to the Delphi 7 WSDL Importer-generated Interface proxy unit.
- Add a web reference by choosing the Add Web Reference command from the context menu of the Project Manager.

Implementation Notes

The following notes address discrete issues that you may encounter when porting web service client applications.

Web Service Server Interoperability

Delphi 7 and the .NET SOAP implementations differ slightly. You need to set certain options on the server (TSOAPDomConv.Options property) to succeed in getting multiple clients to work. Set the following options to ensure that both client applications can process the SOAP packages and can transfer the correct encoding:

Copy Code

    [soTryAllSchema, soRootRefNodesToBody, soUTF8InHeader, soUTF8EncodeXML]

Handling Exceptions

The following table shows the corresponding exceptions between Delphi 7 and the .NET Framework.

Delphi 7 Exception | .NET Framework Exception
ERemotableException | System.Web.Services.Protocols. SoapException
ESOAPHTTPException | System.Net.WebException

Faultcodes

In Delphi 7, the ERemotableException.FaultCode property returns a qualified name, such as SOAP-ENV:Client.Login. You must then extract the code using the ExtractLocalName function. The .NET Framework SoapException class provides the SoapException.Code.Name property directly.

Monitoring SOAP Packets

In Delphi 7, the THTTPRIO component provides OnBeforeExecute and OnAfterExecute events, which allow you to monitor requests and responses. You can implement similar functionality using the .NET Framework SoapExtension class. The following is part of an example that implements this functionality. You can find the full example on Borland's CodeCentral. The link is included in the link list at the end of this topic.

Copy Code

    uses
      System.Xml, System.Web.Services, System.Web.Services.Protocols, System.IO;

    type
      TSoapMessageEvent = procedure (Sender: TObject; const Xml: string) of object;

      TSoapMonitor = class(TObject)
      private
        FOnRequest: TSoapMessageEvent;
        FOnResponse: TSoapMessageEvent;
      protected
        procedure DoRequest(const Xml: string);
        procedure DoResponse(const Xml: string);
      public
        class function FormatXmlData(const Xml: string): string; static;
        property OnRequest: TSoapMessageEvent add FOnRequest remove FOnRequest;
        property OnResponse: TSoapMessageEvent add FOnResponse remove FOnResponse;
      end;
        .
        .
        .
    { TSoapMonitor }

    procedure TSoapMonitor.DoRequest(const Xml: string);
    begin
      if Assigned(FOnRequest) then
        FOnRequest(Self, Xml);
    end;

    procedure TSoapMonitor.DoResponse(const Xml: string);
    begin
      if Assigned(FOnResponse) then
        FOnResponse(Self, Xml);
    end;

    class function TSoapMonitor.FormatXmlData(const Xml: string): string;
    var
      Doc: XmlDocument;
      Sw: StringWriter;
      Xw: XmlTextWriter;
    begin
      Doc := XmlDocument.Create;
      Doc.LoadXml(Xml);
      Sw := StringWriter.Create;
      Xw := XmlTextWriter.Create(sw);
      Xw.Formatting := Formatting.Indented;
      Xw.Indentation := 2;
      Xw.IndentChar := ' ';
      doc.Save(xw);
        Result := sw.ToString;
      Xw.Close;
      Sw.Close;
    end;

Working with SOAP Headers

In Delphi 7, you are required to send the header before every method call. The header object is freed after the call. In the .NET Framework, the header class persists after calling a method, until new is assigned, or until the header class is cleared by assigning nil.

SOAP Attachments

The .NET Framework does not support MIME attachments. Delphi 7 SOAP does not support DIME attachments.

See Also

ASP.NET Web Services Overview

Porting a Delphi for Win32 Web Service Client Application to Delphi for .NET

CodeCentral Monitoring SOAP Packets Example

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!