Kotlin, Software Development

Kotlin – SOAP Web Service Client Example

This post shows how to consume a SOAP Web Service using a client application in Kotlin. Although we need Java, we code everything in Kotlin.

Create a SOAP Web Service in Kotlin

Before creating a SOAP Web Service in Kotlin, we must make 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. Also, we need that service running to access its WSDL.

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. Also, the IDE will use the artifacts to run the SOAP client.

The Web Service server runs on localhost:8080. Hence, 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.

Kotlin SOAP Web Service Client

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 client locally within the IDE.

 

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

Kotlin SOAP Web Service Client

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 create the SOAP Web Service client in Kotlin codes. Note that class HiHelloWSService and the interface HiHelloWS come from the jar file we imported into the IDE. Then, our Web Service client in Kotlin will look like the following codes.

We basically just reused the classes and interfaces from the generated jar file. When we run our codes, we get the following output. Please note that the SOAP Web Service must be running before we run the SOAP Web Service client.

Kotlin SOAP Web Service Client

With these Kotlin codes as a base example, we can proceed to build real SOAP Web Service clients.

 

Loading

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like