为什么JAX-WS客户端在运行时访问WSDL? [英] Why does a JAX-WS client access the WSDL at run-time?

查看:69
本文介绍了为什么JAX-WS客户端在运行时访问WSDL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用wsimport生成JAX-WS客户端后

After generating JAX-WS client using the wsimport

wsimport -keep WebService.wsdl

JAX-WS在运行时必须寻找wsdl位置的原因是什么?
这是一个错误吗?

What reason does JAX-WS have to look for the wsdl location at run time?
Is this a bug?

我发现了这篇很棒的文章: JAX-WS客户端:什么是正确的本地WSDL的路径?

I found this great post: JAX-WS client : what's the correct path to access the local WSDL?

但是它没有说明为什么我们在运行时需要wsdl

but it doesn't say why do we need the wsdl at runtime

推荐答案

这是一个错误吗?

Is this a bug?

不,这不是bug,但从概念上讲是合理的.

No, this is not a bug, but reasonable from a conceptual point of view.

JAX-WS在运行时必须寻找wsdl位置的原因是什么?

What reason does JAX-WS have to look for the wsdl location at run time?

在构建时,您是从WSDL生成类的,这意味着您需要知道服务支持哪种操作以及消息具有什么结构(又称为portTypestypesmessages).

At build-time, you generate classes from the WSDL which means you need to know what kind of operations the service supports and what structure the messages have (aka portTypes, types, messages).

在运行时,许多不同的信息会发挥作用.例如,服务运行的实际地址可能已更改. bindings变得相关:消息应该以SOAP 1.1或1.2发送还是两种格式都可以?此外,各种策略(安全性,可靠的消息传递等)可能会附加到该服务.所有这些都是动态的,并且在构建时几乎无关紧要.理想情况下,您应该能够将客户指向使用相同结构的其他服务,并且该服务应该开箱即用.

At run-time a whole lot of different information comes into play. For instance, the actual address the service runs on might have changed. The bindings become relevant: Should messages be sent in SOAP 1.1 or 1.2 or are both formats ok? Futhermore, all sorts of policies (security, reliable messaging, etc.) might be attached to the service. All these things are dynamic and mostly irrelevant at build time. Ideally, you should be able to point your client at a different service that uses the same structure and it should work out of the box.

我想回答另一个我认为您可能会遇到的问题:

I'd like to answer another question I think you might have:

在只有一项永不更改的服务的情况下,这不是总开销吗?

Isn't this a total overhead in cases where there is just one service that never changes?

是的.如果只有一个带有特定WSDL的服务,并且该服务永远不会从其构建时状态发生变化,那么就不必在运行时重新加载WSDL,这会浪费资源.但是,如果JAX-WS不允许出现更复杂的情况,如绑定或策略之类的信息确实发生更改,或者该服务的端点不止一个,那么它将做得很糟糕.

Yes, it is. In cases where there is single service with a particular WSDL that never ever changes from its build-time state, reloading the WSDL at run-time is unnecessary and a waste of ressources. But JAX-WS would do a terrible job if it wouldn't allow for more complicated scenarios where information such as bindings or policies do change or where there is more than a single endpoint for the service.

尽管如此,大多数JAX-WS实现的确允许某种机制在本地存储WSDL,而不在运行时将其加载以进行调用.在RI中,只需将@WebServiceClient中的wsdlLocation指向类路径上的文件即可.

Nonetheless, most JAX-WS implementations do allow for some mechanism to store the WSDL locally and not load it for invocations at runtime. In the RI, simply pointing the wsdlLocation in your @WebServiceClient to the file on the classpath should do the trick.

这篇关于为什么JAX-WS客户端在运行时访问WSDL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆