Why does a JAX-WS client access the WSDL at run-time?

南楼画角 提交于 2020-01-13 09:13:35

问题


After generating JAX-WS client using the wsimport

wsimport -keep WebService.wsdl

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

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

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


回答1:


Is this a bug?

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

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

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).

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?

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.

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.



来源:https://stackoverflow.com/questions/20101009/why-does-a-jax-ws-client-access-the-wsdl-at-run-time

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!