Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Advantages of using a Dynamic Client with JAX-WS

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.

like image 951
jconlin Avatar asked Nov 13 '09 17:11

jconlin


2 Answers

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.

like image 103
Pascal Thivent Avatar answered Sep 28 '22 11:09

Pascal Thivent


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:

  1. parse the wsdl and schema
  2. generate code
  3. compile the code

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.

like image 45
bmargulies Avatar answered Sep 28 '22 11:09

bmargulies