使用带有JAX-WS服务的动态客户端与仅使用生成的客户端类相比有什么优势?有什么缺点?
**对于我的特定情况,我使用Apache CXF,我不确定其他库允许“动态”客户端.
– 我想我不需要添加这个,但是……我正在寻找非显而易见的(我知道……主观的)优点.我不需要别人告诉我不使用生成的类的优点是我不需要生成类.
解决方法
那么,CXF文档非常清楚
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.
换句话说,您不需要类的定义,如下面的文档示例所示:
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance(); Client client = dcf.createClient("echo.wsdl"); Object[] res = client.invoke("echo","test echo"); System.out.println("Echo response: " + res[0]);
关于缺点,它们非常明显(这是付出的代价):你正在操纵字符串,你失去了强烈的打字.