Software Development

Kotlin – SOAP Web Service Client Example

This post demonstrates how to consume a SOAP Web Service using a client application written in Kotlin. We need Java, thought! Kotlin runs on the Java platform (JVM).

Create a SOAP Web Service in Kotlin

Before we create a SOAP Web Service in Kotlin, we have to create a SOAP Web Service. The Kotlin codes on this post will work with that SOAP Web Service because we will use its WSDL to generate artifacts.

Generate JAX-WS Portable Artifacts

Before we code in Kotlin, we need to generate some artifacts using the wsimport command. At this point, we do not need to code anything yet. We are merely setting up our IDE for development. The IDE will use the artifacts to run the SOAP client.

The Web Service server runs on localhost:8080, and its WSDL is available via http://localhost:8080/?wsdl. After generating the artifacts, we get a jar file – soap-client.jar. The filename is arbitrary, and we can choose any name we want.

Then, we reference the jar file in our IDE or via the classpath. Referencing the jar file in our IDE enables it to run our Kotlin SOAP Web Service locally within the IDE.

 

Next, we attach the jar file to the Kotlin Java runtime.

Once we attached the soap-client.jar file, we can see it in the list of classes under the Kotlin runtime configuration.

The Web Service Client in Kotlin

Lastly, we have the SOAP Web Service client in Kotlin codes. The class HiHelloWSService and the interface HiHelloWS come from the jar file we imported into the IDE.

We basically just reused

Sample Output

Note that the SOAP Web Service must be running before we run the SOAP Web Service client.

Got comments, or suggestions? Please visit our Facebook page!

You Might Also Like