Click here to Skip to main content
15,792,628 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a WCF web service with security mode set to TransportWithMessageCredential. My problem is how do you set the authentication header to a Java JAX-WS client. I generated the client using Netbeans client generation and i am able to pass the credentials by right clicking the service reference and setting the credentials there, but how can you do this in code? I Tried the following but it didnt work:

MyService service = new MyService();
IMyService iService = service.getWSHttpBindingIMyService();

BindingProvider bp = (BindingProvider) iService;
Map r = bp.getRequestContext();

r.put(BindingProvider.PASSWORD_PROPERTY, "password");
r.put(BindingProvider.USERNAME_PROPERTY, "username");

First link on google: Application Authentication With JAX-WS[^]

I hope that solves the problem.
Share this answer
huotari 3-Oct-12 5:20am    
Thank you for relying, but it didn't work. I get the following exception:

3.10.2012 12:14:38 [] parse
INFO: WSP5018: Loaded WSIT configuration from file: "path"/build/classes/META-INF/wsit-client.xml.
3.10.2012 12:14:39 com.sun.xml.wss.impl.misc.DefaultCallbackHandler handleUsernameCallback
SEVERE: WSS1500: Username Handler Not Configured properly using Callback and is null. (not cofigured)
3.10.2012 12:14:39 com.sun.xml.wss.impl.misc.DefaultSecurityEnvironmentImpl getUsername
SEVERE: WSS0216: An Error occurred using Callback Handler for : UsernameCallback
3.10.2012 12:14:39 com.sun.xml.wss.impl.misc.DefaultSecurityEnvironmentImpl getUsername
SEVERE: WSS0217: An Error occurred using Callback Handler handle() Method. Username Handler Not Configured
TorstenH. 3-Oct-12 5:40am    
Please develop. It can't only take 11 minutes to figure out.

The exception says something about Username Handler. I'd discover that path.
wsimport -keep -verbose -Xdebug -XadditionalHeaders -wsdllocation ~/Desktop/ProOnDemandService.wsdl https://path/YourService?WSDL

This command will generate the Security/Additional Headers as an Object, which can be passed to the Business method.

Here is the Code to Invoke the Client with Authentication ---

YourStub stub = new YourStub();

QAPortType portType = stub.getQAPortType();

QAQueryHeader queryHeader = createHeaderInfo(portType);
AuthHeaderObject auth = new AuthHeaderObject();
AuthHeaderContainer queryHeader = new AuthHeaderContainer();

YourRequestObject reqObject = new YourRequestObject();
YourResponseObject sysInfoOne = reqObject.methodName(reqObject, queryHeader,
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900