简体   繁体   English

使用带有JAX-WS的动态客户端的优点

[英]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? 使用带有JAX-WS服务的动态客户端与仅使用生成的客户端类相比有什么优势? What are the disadvantages? 有什么缺点?

**For my particular case I am using Apache CXF, I'm not sure what other libraries allow "dynamic" clients. **对于我的特定情况,我使用Apache CXF,我不确定其他库允许“动态”客户端。

-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文档非常清楚动态客户端的优势:

CXF supports several alternatives to allow an application to communicate with a service without the SEI and data classes. CXF支持多种替代方案,允许应用程序在没有SEI和数据类的情况下与服务进行通信。 JAX-WS specified the JAX-WS Dispatch API, as well as the Provider interface for reading and writing XML. JAX-WS指定了JAX-WS Dispatch API,以及用于读取和写入XML的Provider接口。 This page, however, describes the dynamic client facility of CXF. 但是,此页面描述了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 . 对于动态客户端,CXF在运行时生成SEI和bean类,并允许您通过使用对象的API调用操作,或者使用反射调用完整代理

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: 动态客户端速度较慢,因为代码(我写了一些代码)必须:

  1. parse the wsdl and schema 解析wsdl和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. 它更麻烦,因为您的数据模型中没有任何复杂对象的bean类。 You need to use reflection. 你需要使用反射。

Keep in mind that the dynamic client is different from the invocation interface. 请记住,动态客户端与调用接口不同。

The advantage to using a dynamic client is that you don't need to have generated the stubs before run time. 使用动态客户端的优点是您不需要在运行时之前生成存根。 This allows you to generically invoke services that you may not know about at run time. 这允许您通常调用在运行时可能不了解的服务。

The generated client classes are great if you know precisely what web-service your client code is going to call and that it isn't going to change over the lifetime of your client. 如果您准确了解客户端代码将要调用的Web服务以及在客户端的生命周期内不会更改,则生成的客户端类很棒。

If either of these isn't the case then you will need to think about how your client will handle these situations. 如果其中任何一种情况不是这样,那么您需要考虑客户如何处理这些情况。 The Dispatch API gives you the flexibility to generate the web-service call on the fly without having an apriori knowledge of the service being accessed. Dispatch API使您可以灵活地动态生成Web服务调用,而无需熟悉所访问的服务。 This obviously comes at the cost of your code needing to support the configuration options required to build that call. 这显然需要代码来支持构建该调用所需的配置选项。

With all this said, a certain amount of responsibility does lie with the developer/maintainer of the server side interface to not introduce changes that will break client code. 尽管如此,服务器端接口的开发人员/维护人员确实承担了一定的责任,不会引入会破坏客户端代码的更改。

I had a similar conversation with a co-worker the other day. 前几天我与同事进行了类似的谈话。 He was using the Spring client, that requires the use of an Interface to compile the client against, but then Spring injects the actual code to make the interface work. 他正在使用Spring客户端,它需要使用一个接口来编译客户端,然后Spring注入实际代码以使接口工作。 It basically boiled down to the oldest of saws between us, things like dynamic proxies usually introduce some sort of performance tax, he's ok with that, I started out life writing device drivers, and so am thoroughly prejudiced in favor of speed. 它基本上归结为我们之间最古老的锯,像动态代理这样的东西通常会引入某种性能税,他没关系,我开始写生活中的设备驱动程序,所以我对速度有着极大的偏见。 Faster/smaller wins as far as I'm concerned, and since I'm not constrained to such limited environments...heck my Droid phone makes all the systems I worked on, including mainframes, in my first 10 years professionally look puny, I'll come down on the side of speed. 就我而言,更快/更小的胜利,因为我不受限于这样有限的环境......我的Droid手机让我所有的系统,包括大型机,在我的前10年专业看起来微不足道,我会站在速度的一边。 The common rejoinder for this is that there are many other bottlenecks that are the "real" problem, and that this issue is insignificant against them....and it may be true...but every little bit helps. 对此的共同反驳是,还有许多其他瓶颈是“真正的”问题,而且这个问题对他们来说微不足道......而且可能是真的......但每一点点都有帮助。 If you read the stuff from Steve Souders and his compatriots...users can notice a change of as little as 400 milliseconds...they don't necessarily register that things are slower, but their reaction is different. 如果你读过Steve Souders和他的同胞们的东西......用户可以注意到400毫秒的变化......他们并不一定注意到事情变慢了,但他们的反应是不同的。 So since I can't do anything about network speed, database index overhead, etc, then I can at least do the best job I can with the things that I can influence. 因为我无法对网络速度,数据库索引开销等做任何事情,所以我至少可以用我可以影响的事情做最好的工作。 Whew! 呼! Sorry 'bout that!! 对不起'那个!! Stepping off the soapbox now! 现在就离开肥皂盒吧! ;) ;)

DII ( D ynamic I nvocation I nterface) Client: With the DII, a client can call a remote procedure even if the signature of the remote procedure or the name of the service are unknown until runtime. DII(d ynamic nvocation 覆盖整个院落)客户端:随着DII,客户可以调用即使远程程序或服务的名称的签名是未知的,直到运行时的远程过程。

Because of its flexibility, a DII client can be used in a service broker that dynamically discovers services, configures the remote calls, and executes the calls. 由于其灵活性,可以在服务代理中使用DII客户端,该服务代理动态地发现服务,配置远程调用并执行调用。

  • Advantages 好处

    • Here we have to create simple java interface describing the operations supported by the web service to access. 在这里,我们必须创建简单的java接口,描述Web服务支持访问的操作。 So no need auto generated stubs to access the service. 因此,不需要自动生成的存根来访问服务。
    • Using endpoint it generates WSDL and Stubs on the fly ie at run-time. 使用端点,它即时生成WSDL和Stubs,即在运行时。
  • Disadvantages 缺点

    • Even in this style we have to know the web service before the creating client. 即使在这种风格中,我们也必须在创建客户端之前了解Web服务。
    • Comparing to Generated Stub(GS) it works slowly because of WSDL and stubs generates at run-time. Generated Stub(GS)相比,由于WSDL和存根在运行时生成,因此它的工作速度很慢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM