Is it possible to add headers to the xml? We can add http headers, but we need to add information to the envelope header.
We are using wsdl2apex and following the documentation here:
https://developer.salesforce.com/page/Apex_Web_Services_and_Callouts
public S3.Status DeleteObject(String Bucket,String Key,String AWSAccessKeyId,DateTime Timestamp,String Signature,String Credential) {
S3.DeleteObject_element request_x = new S3.DeleteObject_element();
S3.DeleteObjectResponse_element response_x;
request_x.Bucket = Bucket;
request_x.Key = Key;
request_x.AWSAccessKeyId = AWSAccessKeyId;
request_x.Timestamp = Timestamp;
request_x.Signature = Signature;
request_x.Credential = Credential;
request.inputHttpHeaders_x = new Map<String, String>();
request_x.inputHttpHeaders_x.put('myHeader', 'myValue'); // this adds to the http headers, how can we put this in the <env: header />
Map<String, S3.DeleteObjectResponse_element> response_map_x = new Map<String, S3.DeleteObjectResponse_element>();
response_map_x.put('response_x', response_x);
WebServiceCallout.invoke(
this,
request_x,
response_map_x,
new String[]{endpoint_x,
'',
'http://s3.amazonaws.com/doc/2006-03-01/',
'DeleteObject',
'http://s3.amazonaws.com/doc/2006-03-01/',
'DeleteObjectResponse',
'S3.DeleteObjectResponse_element'}
);
response_x = response_map_x.get('response_x');
return response_x.DeleteObjectResponse;
}
This is the generated SOAP xml:
Is it possible to set the <env: Header>
with information?
Best Answer
You can generate SOAP headers for use with
WebServiceCallout.invoke
using a member and a corresponding string with the_hns
suffix.For reference, Wsdl2Apex processes this around Line 86 of the BindingClass.java file.
You will need to create an inner class to contain the header data.
Here is an example from the UPS XAV Service WSDL. The code was generated using the FuseIT SFDC Explorer Wsdl2Apex function (Disclosure, this is my current employer).
If you do want to go down the HttpRequest path as Keith commented, the FuseIT SFDC Explorer tool can also generate code using the HttpRequest. I cover this in my Dreamforce 2014 presentation.