views:

351

answers:

1

Hi,

how can I access a webservice through a basic http authentification? I am using the netbeans built in webservice client features. But when I try to access the webservice, I get an exception with a 401 auth failed error message.

How can I pass the right username and password?

Thank you!

A: 

You could use BindingProvider or WSBindingProvider class to access a Web Service through a basic http authentification. The code is as follows.

XxxService service = new XxxService();
Xxx port = service.getXxxPort();

Map<String, Object> reqContext = ((BindingProvider)port).getRequestContext();
reqContext.put(BindingProvider.USERNAME_PROPERTY, "username");
reqContext.put(BindingProvider.PASSWORD_PROPERTY, "password");
tomute
This will work if the WSDL is not protected himself by Basic Http Authentication
snowflake