Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access a .Net web service from a Delphi Win32 application?

What options do I have if I want to enable a Delphi Win32 application to consume a .Net webservice?

Is it possible to interact directly? Or do I have to resort to a middleman-software communicating to the Delphi application per COM for instance?

The Delphi application in question is written in Delphi 2006 but is planned to be updated to Delphi XE soon.

like image 861
Amenti Avatar asked Dec 17 '22 14:12

Amenti


2 Answers

While your project is open in Delphi IDE, go to:

File | New | Other... | Delphi Projects | WebServices | WSDL Importer

Now WSDL importer wizard will start. Type in WSDL address for your webservice, and press Next. It will show you different options about how to process the WSDL. You can change the options if needed. Eventually, when the wizard is finished, you will have a new unit in your project which contains client-side wrapper classes and interfaces for your webservice. Now you can use this class in different ways. The simplest method is to call a function which is named Get(Your_WebService_Name). For example if your webservice name is TestWebService, the function will be named GetTestWebService.

The function will return an interface which represents the same interface as your webservice, now you can call the methods of this interface, and it will automatically transfer the request to the remote server, and return the result back to you. An example source code could look like this:

var
  MyTestService: ITestService;
begin
  MyTestService := GetTestService();
  MyTestService.TestMethod;
end;

Another option is that you setup a THttpRio object manually, and use it. Actually that is what that Get(Your_WebService_Name) function does internally.

like image 88
vcldeveloper Avatar answered May 13 '23 22:05

vcldeveloper


Just add the line InvRegistry.RegisterInvokeOptions(TypeInfo(xxx), ioDocument); to your initialize section of the generated imported file. It will work as a charm.
NOTE: xxx must be replaced with your imported web service class name.

like image 21
Diego Rodriguez Avatar answered May 14 '23 00:05

Diego Rodriguez