java - 在同一地址上发布两个 Web 服务

标签 java web-services jax-ws

我有一个关于部署 Web 服务的简单问题。目前我有两个端点,见下文:

Endpoint.publish("http://localhost:8000/eCalcWS/eCalc", new eCalc());

Endpoint.publish("http://localhost:8001/eCalcWS/eCalc_service", new eCalc_service());

同一个地址上是否可以有两个网络服务?我该怎么做?

最佳答案

不幸的是,你不能按照你想要的方式进行。
其设计是每个端点都与 Web 服务实现者相关联。
来自 spec :

The Endpoint class can be used to create and publish Web service endpoints. An endpoint consists of an object that acts as the Web service implementation (called here implementor) plus some configuration information, e.g. a Binding

发布(我的重点):

publish(String address, Object implementor)
Creates and publishes an Endpoint for the given implementor. The binding is chosen by default based on the URL scheme of the provided address (which must be a URL). If a suitable binding if found, the endpoint is created then published as if the Endpoint.publish(String address) method had been called. The created Endpoint is then returned as the value of the method.

我记得我很久以前也遇到过这个问题,这真的很糟糕,因为我需要将 2-3 个不同的实现与不同的 URL 关联起来,但这是不可能的(获取地址已经绑定(bind)错误)。
如果我记得的话,我解决这个问题的方法是创建自己的调度程序。
我发布了一个端点,它接受多个端点的 Web 服务请求,并将请求分派(dispatch)到相应的实现。我直接处理 SOAP 消息。
但这对我来说是可能的,因为 xml 消息非常简单而且很少。
对于您来说,如果您的 Web 服务实现并不简单,并且消息复杂,并且期望有很多客户端,那么我建议您在不同的端点中发布,因为端点实际上只是在后台部署了一个简单 http 服务器。

关于java - 在同一地址上发布两个 Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13239923/

相关文章:

java - 从对象中私有(private)的关键字段获取 MethodHandle 列表

Java ArrayList - 返回 ArrayList

java - 检索最接近用户给定的地理点(纬度/经度)的最佳方法,我有存储在 MySQL 数据库中的所有地理点的列表

java - 来自 jaxws-tools :3. 0.0 的 Wsimport 在 ClassNotFoundException 上崩溃

java - 在 JAX-WS 中重命名参数名称

java - 如何在 websphere 上部署同一个 web 服务的多个版本

Java字符串太长?

java - 与项目阅读器一起使用的正确编码是什么

web-services - 如何使用 REST Web 服务上传包含元数据的文件?

jquery - Ajax 调用 Web 服务失败