线程“main”中的异常javax.xml.ws.WebServiceException:无法访问WSDL ....(jax-ws)

时间:2013-02-06 13:43:03

标签: java web-services jax-ws

我创建了一个简单的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)它正在工作。请帮忙。

这是客户端文件。     import 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());

    }

}

1 个答案:

答案 0 :(得分:2)

所以你不清楚什么?例外情况:javax.xml.ws.WebServiceException: Failed to access the WSDL清楚地告诉您,您的网络服务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.
}

我已经使用基本身份验证代码,以后您可能需要它。目前你可以删除它。