You need to sign in to do that
Don't have an account?
WebServiceCallout and WSSE Authentiction
Hi Guys,
I'm working on integration with some web service that requires WSSE authentication.
WSSE Authentication requires special SOAP Header that can look like below:
<env:Header>
<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2003/06/secext">
<wsse:UsernameToken>
<wsse:Username>test</wsse:Username>
<wsse:Password>123</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</env:Header>
So, I decided to use WebServiceCallout class to invoke that web service methods. I also found a way how to add SOAP header but I spent a lot of time reading documentation and trying different things to figure out how to add "wsse" prefix for the lements in this header without any success...
The maximum I was able to produce is:
<env:Header>
<n1:Security xmlns:n1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<usernameToken>
<username>test</username>
<password>123</password>
</usernameToken>
</n1:Security>
</env:Header>
Do anybody know about any workaround to specify "wsse" prefix?
I really don't want to go with Http classes solution yet hoping that there could be some solution I don't know about. Please advise.
Thanks in advance!
As per the xml namespaces spec, the actual prefix doesn't matter, all that matters is the URI that the prefix is bound to. What you have is close to what you want, you just need to fix the namespace URI, and the capitalization of the elements.
All Answers
As per the xml namespaces spec, the actual prefix doesn't matter, all that matters is the URI that the prefix is bound to. What you have is close to what you want, you just need to fix the namespace URI, and the capitalization of the elements.
Thanks a lot
for your reply, SimonF!
I made changes in the code to have the capitalization. I left URI as is because it's suggested by web service provider.
I didn't find a way how to make "n1" prefix for all elments inside "Security" one, probably that's why I still have UnAuthorized response from that web service...
Can you post your code.
Well, here is my code (of course it's simplified to exclude sensitive information):
public class SoapSecurity {
public UsernameToken UsernameToken = new UsernameToken();
private String[] UsernameToken_type_info = new String[] {'UsernameToken','','ComplexType','1','1','false'};
private String[] apex_schema_type_info = new String[] {'','true','false'};
private String[] field_order_type_info = new String[]{'UsernameToken'};
}
public class UsernameToken {
public String Username = 'test';
public String Password = '123';
private String[] Username_type_info = new String[] {'Username','','string','1','1','false'};
private String[] Password_type_info = new String[] {'Password','','string','1','1','false'};
private String[] apex_schema_type_info = new String[] {'','true','false'};
private String[] field_order_type_info = new String[]{'Username', 'Password'};
}
public class ServicePort {
public SoapSecurity Security = new SoapSecurity();
private String Security_hns = 'Security=http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
...
...
public DWebService.SendDataResponse_element sendData(String userId, DataRecord[] data) {
WebServiceCallout.invoke(
this,
request_x,
response_map_x,
new String[] {
endpoint_x,
'',
'http://www.demo.com/DWebService/schema/beans','sendDataRequest',
'http://www.demo.com/DWebService/schema/beans',
'sendDataResponse','DWebService.sendDataResponse_element'
}
);
...
...
}
}
Please let me know if I need to provide more information.
Thanks in advance!
Well, I've resolved my issue already! SimonF was right with the wsse prefix is not important. The only think I corrected to get it work is right namespaces for all ements in my SOAP header. So, thanks SimonF again!
Facing same issue, can you help me?
I wanted to craete below response :
My class is :
I have tried alot but in vain, can anyone tell me how should i code to get the same resonse?