Dear Nandana,

Thank you very much for your reply. I've read through the tutorial you
sent me and I'm able to engage Rampart in my Axis2 client. However, when
I sent the request I got the error "WSDoAllReceiver: Incoming message
does not contain required Security header". It seems to me that the WSS
header was not added to the SOAP request. Below is my client side code:

                        ConfigurationContext ctx =
ConfigurationContextFactory
        
.createConfigurationContextFromFileSystem(
                                                        "repository",
null);
                        TradeRetrieverServiceStub stub = new
TradeRetrieverServiceStub(
                                        ctx,            
        
ConfigReader.getInstance().readConfig().getEndPoint());
                        ServiceClient sc = stub._getServiceClient();
                        sc.engageModule("rampart");
                        ServiceClient client = stub._getServiceClient();
                        Options options = client.getOptions();
        
options.setUserName(ConfigReader.getInstance().readConfig()
                                        .getUsername());
        
options.setPassword(ConfigReader.getInstance().readConfig()
                                        .getPassword());
                        GetTrades request = new GetTrades();
                        TradeFilterDTO filter = new TradeFilterDTO();
                        Calendar cal = Calendar.getInstance();
                        cal.set(cal.DATE, cal.get(cal.DATE) - 1);
                        filter.setFromModifyTime(cal);
                        request.setFilter(filter);
                        GetTradesResponse resp =
stub.getTrades(request);
        
System.out.println(resp.get_return().getDepositTrades());

The server side is also based on Axis2 and it uses Rampart to check the
username and password. 

Please let me know if my code is correct, thanks a lot!

Regards,
Mai Sun

-----Original Message-----
From: Nandana Mihindukulasooriya [mailto:[EMAIL PROTECTED] 
Sent: 31 March 2008 13:38
To: [email protected]
Subject: Re: How to add WS-Security header in Axis2 client

Hi Mai Sun,

>  is there a way to set username and
> password programatically when invoking a web service that requires 
> WS-Security header?

use
    ServiceClient sc = stub._getServiceClient();
    Options options = sc.getOptions();
    options.setUserName("username");
    options.setPassword("password");

take a look at this tutorial [1] for more information.

thanks,
/nandana

[1] - http://wso2.org/library/3190

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to