简体   繁体   English

如何最好地在Web应用程序中实现Web服务客户端?

[英]How do I best implement a web service client inside a web application?

I've got a service running at a fixed location in the network, with a WSDL attached etc. I can easily create a jax-ws client with wsimport and the usual stuff when doing this stand-alone, but I'd really like to be able to call this service from inside another web application. 我已经在网络中的固定位置运行了服务,并附加了WSDL等。在执行此独立操作时,我可以轻松地用wsimport和常用的东西创建一个jax-ws客户端,但是我真的很想能够从另一个Web应用程序内部调用此服务。

Unfortunately I'm running into some gotchas here. 不幸的是,我在这里遇到了一些麻烦。 For one, everything works pretty well in a regular web container, but not on jboss, which apparently puts some incompatible classes in the endorsed directory making deployment fail with: 首先,一切都可以在常规的Web容器中很好地运行,但是在jboss上却不能,这显然在认可目录中放置了一些不兼容的类,从而使部署失败:

java.lang.ClassCastException: com.sun.xml.ws.client.WSServiceDelegate cannot be cast to javax.xml.ws.spi.ServiceDelegate21

There's a blog entry somewhere that proposes to fix this by deleting the endorsed jax-ws jars, but this might end up breaking something else on this particular server and so I was wondering if there isn't a better way to isolate this further? 某处有一个博客条目建议通过删除认可的jax-ws jar来解决此问题,但这可能最终会破坏此特定服务器上的其他内容,因此我想知道是否有更好的方法来进一步隔离此问题? Completely relying on j2ee specific support is possibly an option but I'd really like to retain the ability to deploy the app on a simple web container as well (jetty, tomcat, ...). 完全依赖j2ee特定的支持可能是一种选择,但是我真的很想保留将应用程序部署在简单的Web容器(jetty,tomcat等)上的能力。

My advice is to forget JAX-WS on the client. 我的建议是忘记客户端上的JAX-WS。 It's complicated and not as portable as it thinks it is, and is often an integration headache. 它很复杂,并不像它想像的那样可移植,并且通常是一个集成难题。

I suggest a more lightweight web service client, such as Spring-WS's WebServiceTemplate . 我建议使用更轻量的Web服务客户端,例如Spring-WS的WebServiceTemplate It will support your existing wsimport-generated JAXB bindings, but will ignore the JAX-WS stuff. 它将支持您现有的由wsimport生成的JAXB绑定,但将忽略JAX-WS内容。 It's simple, easy and will run in anything from a full JBoss stack to a Jetty application without butting heads with existing frameworks. 它简单,容易,并且可以在从完整的JBoss堆栈到Jetty应用程序的任何内容中运行,而无需与现有框架打交道。

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

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