1

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

    }

}
4

1 回答 1

3

那么你有什么不清楚的地方?例外: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.
}

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

于 2013-02-07T13:27:58.337 回答