我构建了一个最小的 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。
是否有可能只定义端口?