我能够自己独立运行一个 WebService
和一个 httpServer
,但是当我同时运行它们时,网络服务 wsdl
网址不再有效。我希望这样做,这样我就可以从 javascript 调用 Web 服务到相同的 URL,而不会出现跨源问题。
这可能吗?
public class Main {
public static void main(String[] args) throws Exception {
int port = 8888;
/* This works without httpServer running */
Endpoint.publish("http://localhost:" + port + "/ws/someService", new SomeService());
/* This works without Endpoint running */
HttpServer httpServer = HttpServer.create(new InetSocketAddress(port), 0);
httpServer.createContext("/someHandler", new SomeHandler());
}
}
最佳答案
尝试使用不同的端口。例如,如果您将 8888 用作 Endpoint,则将 8890 或其他名称用于 HttpServer。
EndPoint 使用嵌入式 HTTP 服务器实现,它作为 Java 的一部分包含在内。 因此,您实质上是在尝试在同一个端口上使用两个不同的 HTTP 服务器,我认为这是行不通的。您应该使用不同的端口来完成这项工作。
关于java - (Java) 同时发布 Web Service Endpoint 和 Http Server?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53741167/