Java 使用 Jax-WS Endpoint 发布 WS

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3680600/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 03:26:26  来源:igfitidea点击:

Publishing a WS with Jax-WS Endpoint

javaweb-servicesjax-wsendpoint

提问by daniel

I built a minimal web service and published it using javax.xml.ws.Endpoint. If I try to get the WSDL at http://localhost:1234/AddService?wsdlit works fine.

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

Trying to recieve it at http://192.168.0.133:1234/AddService?wsdl, I don't receive anything. This address is the same as localhost.

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

Is there a posibiility to publish a webservice without providing the address?

是否有可能在不提供地址的情况下发布网络服务?

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());
    }
}

Changing the code to

将代码更改为

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

gets me the wsdl on the IP address but not on localhost.

为我获取 IP 地址上的 wsdl,而不是本地主机上的 wsdl。

Isn't there a posibility to just define the port?

难道不能只定义端口吗?

采纳答案by ivy

Could you try publishing it on 0.0.0.0?

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

回答by sachJuve

Here is my code:

这是我的代码:

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

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

It says The address's path should start with /

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