What are the advantages of using a dynamic client with JAX-WS services as opposed to just using generated client classes? What are the disadvantages?
**For my particular case I am using Apache CXF, I'm not sure what other libraries allow "dynamic" clients.
-I thought I didn't need to add this, but... I'm looking for non-obvious(I know...subjective) advantages. I don't need someone else to tell me that an advantage of not using generated classes is that I don't need to generate classes.
Well, the CXF documentation is pretty clear about the advantages of Dynamic Clients:
CXF supports several alternatives to allow an application to communicate with a service without the SEI and data classes. JAX-WS specified the JAX-WS Dispatch API, as well as the Provider interface for reading and writing XML. This page, however, describes the dynamic client facility of CXF. With dynamic clients, CXF generates SEI and bean classes at runtime, and allows you to invoke operations via APIs that take Objects, or by using reflection to call into full proxies.
In other words, you don't need the definitions of classes as shown in the documentation sample below:
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient("echo.wsdl");
Object[] res = client.invoke("echo", "test echo");
System.out.println("Echo response: " + res[0]);
Regarding the disadvantages, they are pretty obvious (and this is the price to pay): you are manipulating strings, you lost strong typing.
The advantage is avoiding generating and including code. In some environments, that's a problem. If there's no barrier in your environment to including generated code, then the dynamic client is a bad idea, being slower and more cumbersome.
The dynamic client is slower because the code (of which I wrote some) must:
It is more cumbersome because you don't have bean classes for any complex objects in your data model. You need to use reflection.
Keep in mind that the dynamic client is different from the invocation interface.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With