Today, we’ll talk about writing a Java client for exchanging data with a web service using the SOAP protocol specification. Many of the web services that support SOAP have Java libraries that can make this task pretty simple to implement. But if there is no such feature, then it becomes a little tricky, but in this article, I will show you that it’s not as hard as it seems.
At first, you should find out the location of the WSDL file, which describes the functionality offered by a web service. When it’s done, you can simply get the Java code from it that will be able to send any request supported by the web service. There are a bunch of tools that provide wsdl2java transfer, for example: Apache CXF, JAX-WS WS import, and Apache Axis.
To make the code generation more convenient, I used the SoapUI application. There, you may generate the code through any of these tools by using a user-friendly interface; furthermore, it supports not only the tools that generate Java code, but also tools that generate .NET 2.0 artifacts, XML beans, and so on. Just specify the path to the folder with the tool you want to use in global preferences, select it in the ‘Tools’ tab, specify the path to the WSDL file and output directory, and here you go, you have generated your own SOAP library, have fun! Follow the link for more details.
Note: While generating code from WSDL, you may get this error: “Rpc/encoded WSDLs are not supported…”. This means the WSDL has parts with the rpc/encoded style model, which isn’t supported by WS import, CXF, Axis 2., and other tools. If this error appears, use Apache Axis 1. instead.
