21

我构建了一个最小的 Web 服务并使用 javax.xml.ws.Endpoint 发布它。如果我尝试获取 WSDL, http://localhost:1234/AddService?wsdl它可以正常工作。

试图在 收到它http://192.168.0.133:1234/AddService?wsdl,我没有收到任何东西。此地址与 localhost 相同。

是否可以在不提供地址的情况下发布 Web 服务?

package test;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;

@WebService
public class AddService {

    @WebMethod
    public int add(int a, int b){
        return a+b;
    }

    public static void main(String[] args ){
        Endpoint.publish("http://localhost:1234/AddService", new AddService());
    }
}

将代码更改为

Endpoint.publish("http://192.168.0.133:1234/AddService", new AddService());

让我得到 IP 地址上的 wsdl,但不是 localhost。

是否有可能只定义端口?

4

2 回答 2

39

您可以尝试在 0.0.0.0 上发布它吗?

于 2010-09-09T22:20:42.103 回答
-2

这是我的代码:

Endpoint.publish(" http://localhost:8080 ", new ServiceController());

它说地址的路径应该以 / 开头

于 2019-03-07T22:22:37.153 回答