Update: this project is now available on Github

In the previous blog post, I have shown Delphi code examples using Indy TIdHTTP as a client for a basic REST server written using the JAX-RS API, running in Thorntail.

This article shows how a JAX-WS SOAP WebService can be exposed using Thorntail and consumed with Delphi.

For brevity, we will adopt a code-first approach, and use JAX-WS annotations to expose our service under SOAP format.

JAX-WS WebService – the Java EE server

package com.example;

import javax.jws.WebService;
import javax.jws.WebMethod;

   targetNamespace = "http://hello.example.com/")
public class Hello {
    private final String message = "Hello, ";

    public String sayHello(String name) {
        return message + name + ".";

That’s the standard JAX-WS web service code for a simple SOAP endpoint which has one method, sayHello, that takes a String argument and returns a String response.

After building the server with Maven, we launch it from the command line:

>java -jar target/soap-endpoint-thorntail.jar

The server will log the startup and deployment of our web service application:

2019-01-28 09:24:42,517 INFO  [org.jboss.as.server] (main) WFLYSRV0010: Deployed
 "soap-endpoint.war" (runtime-name : "soap-endpoint.war")

To check that the web service is working, we can invoke its WSDL at the endpoint address:


Alternatively, we can use SoapUI to run a first test request:


JAX-WS WebService – the Delphi client

First we create a new command line application.

Then we use the WSDL importer to generate a Delphi binding. This will create a unit ”helloService”, and add it to the project.


Now wee need only to insert a call to the web service in the Delphi code:

program helloWorldClient;


  helloService in 'helloService.pas',
  SysUtils, ActiveX;

  HelloServer: Hello;
  Response: string;

     HelloServer := GetHello;
     Response := HelloServer.sayHello('Delphi');
    on E:Exception do
      Writeln(E.Classname, ': ', E.Message);


Note for older Delphi versions: if we run the Delphi code unmodified, our client will show an exception:

ERemotableException: Unmarshalling Error: unerwartetes Element (URI:"http://hell
o.example.com/", lokal:"arg0"). Erwartete Elemente sind

The fix on the Delphi side is shown below. The last parameter of RegisterInvokeOptions must be changed from ioDocument to ioHasNamespace.

  InvRegistry.RegisterInterface(TypeInfo(Hello), 'http://hello.example.com/', '');
  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(Hello), '');
  InvRegistry.RegisterInvokeOptions(TypeInfo(Hello), ioHasNamespace);

And with this change, the client receives the expected response:

Hello, Delphi.



Thorntail, which is designed for usage in microservice architectures, saves much of the time which is usually needed for creating, deploying, and testing Java EE components (such as JAX-RS and JAX-WS web services). Building a Java EE compliant web service server with Thorntail requires only a basic Java IDE. The resulting server is packaged as a single jar file and can be run instantly from the command line, or can be packaged as a war file ready for deployment in any Java EE compatible application server.


Unmarshalling Error

Example code based on Thorntail docs https://docs.thorntail.io/2.3.0.Final/#_basics

JAX-WS Java API for XML Web Services

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s