1

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:

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.

This is the client file. 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 Answer 1

3

So whats not clear to you? The exception: javax.xml.ws.WebServiceException: Failed to access the WSDL clearly says to you that your web service's WSDL is not accessible within this path: /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?wsdl than create a JAX-WS client like this:

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.