【问题标题】:java.net.ConnectException: Connection timed out: connect in Eclipsejava.net.ConnectException:连接超时:在 Eclipse 中连接
【发布时间】:2016-07-04 02:41:39
【问题描述】:

我正在尝试使用 Eclipse 使用以下公共 Web 服务。 http://www.webservicex.com/globalweather.asmx?wsdl

当我在 java 客户端中执行时,它给出了错误;

java.net.ConnectException: Connection timed out: connect

下面是简单的客户端程序;

public class ClientTest1 
{
    public static void main(String[] args) 
    {
        GlobalWeatherSoapProxy obj1 = new GlobalWeatherSoapProxy();
        try
        {
            System.out.println(obj1.getCitiesByCountry("Japan"));
        }
        catch(Exception e1)
        {
            System.out.println(+e1.getMessage());
        }
    }
}

但奇怪的是,当通过 SOAP UI 使用时,它可以正常工作。因此我认为这与 Eclipse 配置有关。

提前感谢您的帮助。

【问题讨论】:

  • 你是如何从 wsdl 生成类的? cxf, jax-ws?

标签: java eclipse web-services soapui


【解决方案1】:

Eclipse 与它无关。您的代码由 JVM 执行,即使您的开发环境是 Eclipse。连接超时意味着您的客户端无法与端点连接。

您已经以某种方式自动生成了客户端代理,获得了GlobalWeatherSoapProxy。此类将通过加载 WSDL 来获取对端点的引用。或者,可以通过代码提供 url。查看该类的内容以查看端点 URL 的加载方式

您应该会看到类似的内容(查看完整的example

URL url = new URL("http://localhost:9999/ws/hello?wsdl");
QName qname = new QName("http://ws.mkyong.com/", "HelloWorldImplService");
Service service = Service.create(url, qname);
HelloWorld hello = service.getPort(HelloWorld.class);

【讨论】:

    猜你喜欢
    • 2011-08-05
    • 2014-03-01
    • 1970-01-01
    • 2015-09-27
    • 2012-09-29
    • 2014-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多