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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14730564/
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-10-31 17:11:16  来源:igfitidea点击:

Exception in thread "main" javax.xml.ws.WebServiceException: Failed to access the WSDL....(jax-ws)

javaweb-servicesjax-ws

提问by user2010754

I have created a simple jax-ws web service and deployed it successfully. Then I created one client(jax-ws), but while running I am receiving the error below:

我创建了一个简单的 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

But if I create the client (apache) for the same wsdl it is working. Please help.

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

This is the client file.import java.rmi.RemoteException;

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

    }

}

回答by Paulius Matulionis

So whats not clear to you? The exception: javax.xml.ws.WebServiceException: Failed to access the WSDLclearly says to you that your web service's WSDLis not accessible within this path: /WEB-INF/wsdl/HelloService.wsdl.

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

If you've deployed your web service and you are able to access it through URL. For e.g.: http://somehost/somepath/YourService?wsdlthan create a JAX-WSclient like this:

如果您已经部署了 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.
}

I've put the code with the basic authentication as well that you might need it in future. At the moment you can just remove it.

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