我创建了一个简单的 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());
}
}
最佳答案
那么您还有什么不清楚吗?异常:javax.xml.ws.WebServiceException:无法访问 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.
}
我也将代码与基本身份验证放在一起,以便您将来可能需要它。目前您可以将其删除。
关于java - 线程 "main"javax.xml.ws.WebServiceException : Failed to access the WSDL. ...(jax-ws) 中出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14730564/