Is there any documentation or reference on how to add username and password to the transport layer when making an apex callout to consume a SOAP based service?
1 Answer
You can add custom headers as described in SOAP Services: Defining a Class from a WSDL Document, as demonstrated below:
docSample.DocSamplePort stub = new docSample.DocSamplePort();
stub.inputHttpHeaders_x = new Map<String, String>();
//Setting a basic authentication header
stub.inputHttpHeaders_x.put('Authorization', 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==');
//Setting a cookie header
stub.inputHttpHeaders_x.put('Cookie', 'name=value');
//Setting a custom HTTP header
stub.inputHttpHeaders_x.put('myHeader', 'myValue');
String input = 'This is the input string';
String output = stub.EchoString(input);
-
I guess you add credentials with header in this way. Correct? The transport layer to the external system is encrypted.– SfdcBatCommented Dec 19, 2016 at 16:46
-
I hit the service endpoint using soap ui and I get a correct response. I include only username and password in soap ui. But when I hit from salesforce I include username and password in http header like how you described. But I get an exception that the service denied my request. Any idea why?– SfdcBatCommented Dec 19, 2016 at 17:52
-
@SfdcBat I'd have to see a sample of the successful request to know for sure. Perhaps include it in your question?– sfdcfox ♦Commented Dec 19, 2016 at 17:54
-
-
1@SfdcBat - Difficulty all depends on their architecture so it is hard to say. Also, their policies on testing and validation may increase the effort required significantly. As for asking, it never hurts, but I would not expect a quick turn around except for the fact that they most likely already have plans for it in their pipeline or they risk becoming obsolete pretty quickly and no-one will connect to them. Of course I may be misreading the error message you provided so get a second opinion before throwing in the towel.– EricCommented Dec 20, 2016 at 3:11