将 WSDL 与客户端应用程序解耦
我有一个使用 Web 服务的 Java Web 服务客户端。客户端是使用 WSDL2Java 工具生成的。一切正常,直到 Web 服务提供商通过添加非必填字段更改模式对象之一。当调用 Web 服务时,响应应该返回这些架构对象的数组,并且由于返回的对象有一个额外的字段 - 一切都会中断。据我了解,有一种方法可以在不破坏客户端应用程序的情况下进行此类更改。
您能为我指出如何解决这个问题的正确方向吗? 任何建议表示赞赏。 谢谢你, 纳迪亚
I have a java web service client consuming web services. The client is generated using WSDL2Java tool. All works fine until the web service provider changes one of the schema objects by adding a non-required field. When the web service is called, the response is supposed to return an array of these schema objects and since the returned objects have an extra field - everything breaks. From what I understand there is a way to allow for such changes without breaking the client application.
Could you point me in the right direction on how to solve this?
Any suggestion is appreciated.
Thank you,
Nadia
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试为您的客户端使用不同的绑定选项。如果我没记错的话,使用 JAXBRI (od JiBX) 应该可以解决问题。尝试 WSDL2Java -d jaxbri
默认为 adb 更多信息位于此处
Try try using different binding options for your client. If I am not wrong using JAXBRI (od JiBX) should solve the issue. try
WSDL2Java -d jaxbri
The default is adb more info is in here
Web 服务不符合 WSDL?
也许您可以编辑 WSDL 并添加非必需字段
或者 WSDL 是否已更改?
如果 WSDL 发生更改,您需要通过 WSDL2Java 工具重新生成代码。
The web service is not conforming to the WSDL?
Maybe you can edirt the WSDL and add the non-required field
Or is the WSDL changed?
If the WSDL was changed you need to re-generate your code by WSDL2Java tool.
这个问题通常很难解决,这就是为什么面向客户端的 XML 模式不应经常更改。您可以尝试禁用架构验证,但如果架构更改太多,您的客户端应用程序仍然会崩溃。
推荐的企业方法(用行话来说:“松散耦合”)是拥有一个单独的域对象层,并在生成的 Java 类和域对象之间进行映射。您只需在架构更改时更新映射,这不应深入到应用程序的各个层中。但每次架构更改时,您仍然需要重新编译应用程序。
This problem is generally hard to solve, which is why client-facing XML schemas shouldn't change very often. You can try disabling schema validation, but if the schema changes too much, your client aplication will still blow up.
The recommended enterprisey way to do this (in the jargon: 'loose coupling') is to have a separate layer of domain objects and map between the generated Java classes and your domain objects. You just update the mappings when the schema changes, which shouldn't penetrate too far into the layers of your application. But you still need to recompile the application every time the schema changes.