Using RemObjects Hydra to consume a .NET WCF service from Delphi

Using RemObjects Hydra is probably the easiest way to consume a WCF service from Delphi in case you need to support .NET-specific bindings which might require a lot of work to implement on your side but are already available for .NET.

This series of videos shows how you can write a managed Hydra plugin module to consume a WCF service and expose it to a Delphi Hydra host application as a custom interface, delegating the method calls to the WCF service.

01. WCF Service Library

  • Create a new WCF Service Library project:
    • FileNewProject…
    • TemplatesVisual C#WCFWCF Service Library
  • Add a new method to the service contract (interface)
  • Implement the new method
  • Test the service with the WCF test client

02. WCF Service Client Library

  • Create a new class library project:
    • Right-click solution, AddNew Project…
    • InstalledVisual C#Class Library
  • Add service reference (to the service created in the previous step)
  • Delete the default empty class module

03. WCF Service Client Console Application

  • Create a new console project:
    • Right-click solution, AddNew Project…
    • InstalledVisual C#Console Application
  • Add System.ServiceModel reference
  • Add service client library reference
  • Add code to call the service methods
  • Run the console application

04. Hydra C# Plugin Module

  • Create a new Hydra Plugin Library project:
    • Right-click solution, AddNewProject…
    • InstalledVisual C#HydraPlugin Module
  • Create a new Hydra Plugin:
    • Right-click project, AddNew Item…
    • InstalledVisual C# ItemsNon-Visual Plugin
  • Add System.ServiceModel reference
  • Add service client library reference
  • Create a COM-compatible interface
    • Right-click project, AddNew Item…
    • InstalledVisual C# ItemsCodeInterface
    • Declare interface IService1Client (public)
    • Inherit from IHYCrossPlatformInterface (RemObjects.Hydra.CrossPlatform)
    • Add IID
    • Add methods
    • Add CompositeType struct
      • Add StructLayout attribute
      • Add MarshalAs attributes
    • Declare data contract parameter ref on the C# side, const on Delphi side
  • Make the plugin implement the interface by delegating to the WCF service client library

05. Delphi Hydra Host Console Application

  • Create a console application
  • Add Vcl to unit scope names
  • Change the output directory to be the same as the plugin output directory
  • Write code to load the plugin and call its interface
  • Copy and patch uHYCLRWrappers.pas unit to load configuration from a .config file
  • Create the configuration file

You can find the source code here:
https://github.com/tondrej/hydra-wcf-delphi

Leave a Reply

Your email address will not be published. Required fields are marked *