How to Use wsdl2java to Generate Wrapped Response Types in Java SOAP Clients
Автор: vlogize
Загружено: 8 апр. 2025 г.
Просмотров: 6 просмотров
Discover how to configure the `wsdl2java` tool to force a wrapped response return type instead of using out parameters in Java SOAP web services.
---
This video is based on the question https://stackoverflow.com/q/75210578/ asked by the user 'adriangl1997' ( https://stackoverflow.com/u/12315478/ ) and on the answer https://stackoverflow.com/a/76580957/ provided by the user 'Wladimir Diskowski' ( https://stackoverflow.com/u/10384954/ ) at 'Stack Overflow' website. Thanks to these great users and Stackexchange community for their contributions.
Visit these links for original content and any more details, such as alternate solutions, latest updates/developments on topic, comments, revision history etc. For example, the original title of the Question was: wsdl2java - how to force wrapped response return type instead of using out parameters wrapped in Holders?
Also, Content (except music) licensed under CC BY-SA https://meta.stackexchange.com/help/l...
The original Question post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license, and the original Answer post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license.
If anything seems off to you, please feel free to write me at vlogize [AT] gmail [DOT] com.
---
Using wsdl2java for Wrapped Response Types in Java SOAP Clients
When working with SOAP web services in Java, one common frustration developers encounter is the generation of methods that return void, utilizing OUT parameters wrapped in Holder objects. Specifically, using the wsdl2java tool, many may find that the expected behavior—returning a wrapped response type—is not met. Let's explore this problem and how to effectively configure wsdl2java to generate the desired structure.
Understanding the Problem
The Scenario
You have a SOAP web service defined by a WSDL file, and using wsdl2java, you are generating client classes to interact with this service. In a typical scenario, you would like the methods to return response objects directly, making them easier to use without dealing with multiple OUT parameters encased in Holder classes.
Example of Existing Code
Consider the auto-generated interface for the Auth class that looks like this:
[[See Video to Reveal this Text or Code Snippet]]
Here, the login method appears inefficient for consumer code, as it forces clients to manage multiple return objects. Instead, we want:
[[See Video to Reveal this Text or Code Snippet]]
The Solution
To achieve this wrapped response behavior in your generated classes, you can pass the bareMethods parameter to the wsdl2java tool during the configuration of your build file, typically a build.gradle.kts for Kotlin DSL users.
Step-by-Step Instructions
Modify the build.gradle.kts Configuration
Here’s how to update your Gradle configuration:
[[See Video to Reveal this Text or Code Snippet]]
Review the Binding File (Optional)
If you are using a binding file (like bindings.xml), ensure that it is well-configured. Though it may not significantly affect the generation if you include the bareMethods parameter, having:
[[See Video to Reveal this Text or Code Snippet]]
is beneficial for additional configurations.
Regenerate the Client Classes
After adjusting your configuration, run your build process again. The wsdl2java will now generate client methods that return instances of the respective response classes instead of utilizing the Holder parameters, providing a more natural API experience.
Conclusion
By adding the -bareMethods parameter to your wsdl2java configuration, you can successfully force the generation of wrapped response types instead of relying on the typical OUT parameters wrapped in Holder objects. This leads to cleaner, more maintainable client code when interacting with SOAP web services.
For further enhancements or debugging, don’t hesitate to refer back to your WSDL and binding configurations!

Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: