【问题标题】:Exception in thread "main" javax.xml.ws.WebServiceException: Failed to access the WSDL....(jax-ws)线程“主”javax.xml.ws.WebServiceException 中的异常:无法访问 WSDL ....(jax-ws)
【发布时间】:2013-02-06 13:43:03
【问题描述】:

我创建了一个简单的 jax-ws Web 服务并成功部署它。 然后我创建了一个客户端(jax-ws),但在运行时我收到以下错误:

Exception in thread "main" javax.xml.ws.WebServiceException: Failed to access the WSDL  
at: file:./WEB-INF/wsdl/HelloService.wsdl. It failed with:.\WEB-INF\wsdl\HelloService.wsdl

但是,如果我为同一个 wsdl 创建客户端 (apache),它就可以工作。请帮忙。

这是客户端文件。 导入 java.rmi.RemoteException;

public class MainClass {

    public static void main(String[] args) throws RemoteException {

        HelloPortProxy obj = new HelloPortProxy();
        System.out.println(obj.sayhello("Everyone"));
        System.out.println("Count:"+obj.getCheckVal());

    }

}

【问题讨论】:

    标签: java web-services jax-ws


    【解决方案1】:

    那么你有什么不清楚的地方?例外:javax.xml.ws.WebServiceException: Failed to access the WSDL 明确告诉您,您的 Web 服务的 WSDL 在此路径中无法访问:/WEB-INF/wsdl/HelloService.wsdl

    如果您已部署 Web 服务并且可以通过 URL 访问它。例如:http://somehost/somepath/YourService?wsdl 而不是像这样创建JAX-WS 客户端:

    try {        
        final String username = "someusername";
        final String password = "somepassword";
        Authenticator.setDefault(new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(
                        username,
                        password.toCharArray());
            }
        });
        URL url = new URL("");
        QName qname = new QName("http://somehost/somepath/YourService?wsdl", "YourService");
        Service service = Service.create(url, qname);
        YourService proxy = service.getPort(YourService.class);
        Map<String, Object> requestContext = ((BindingProvider) proxy).getRequestContext();
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url.toString());
        requestContext.put(BindingProvider.USERNAME_PROPERTY, username);
        requestContext.put(BindingProvider.PASSWORD_PROPERTY, password);
    } catch (Exception e) {
        //Handle Error.
    }
    

    我已将代码与基本身份验证一起放置,以便您将来可能需要它。目前你可以删除它。

    【讨论】:

      猜你喜欢
      • 2017-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多