Im trying to get the session ID of another user in the same org by sending the following request by using the data from my enterprise wsdl and its an developer edition.

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com">
<urn:organizationId>xxxxxxx</urn:organizationId>
<soapenv:Body>
</soapenv:Body>
</soapenv:Envelope>


But when i send this request i get

Missing SOAP ACTION header but in my wsdl i dont have the action ,its blank how to overcome this problem ?I got totaly struck over here since there is no action though its asking for action header.Following method handles the http request.

public string   processrrequest(string ep,string message,string method)
{

HttpRequest req = new HttpRequest();
req.setEndpoint(ep);
req.setMethod(method);
req.setBody(message);
system.debug('Request::'+req.getbody());
Http http = new Http();
HttpResponse res =http.send(req);
//Dom.Document doc  = res.getbodyDocument();
system.debug('Response::'+res.getbody());
system.debug('Response2::'+res.getStatus());
Dom.Document doc= new Dom.Document();
doc=res.getBodyDocument();
system.debug('doc::'+doc);
return 'hai';
}


Looking at the Partner WSDL, the soapAction for the login operation is the empty string.

    <operation name="login">
<soap:operation soapAction=""/>
<!-- .... -->
</operation>


So you would think that it should be added to the request as such:

HttpRequest req = new HttpRequest();
// ...


However, as you found, passing the empty string to the SOAPAction header in the HTTPRequest results in the following response:

System.HttpResponse[Status=Server Error, StatusCode=500]

It would appear that the Apex HttpRequest.setHeader(string, string) won't send an empty or white-space only header. Without this header Salesforce rejects it as an invalid SOAP request.

After a bit of experimenting, it turns out the Salesforce Partner API doesn't really care what SOAPAction you send to it, as long as it is defined. Try it out with the following code and vary the value sent.

string sessionId = UserInfo.getSessionId();
HttpRequest req = new HttpRequest();
req.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm() + '/services/Soap/u/31.0');
req.setMethod('POST');
//System.debug(req.getBody());
Http http = new Http();
HTTPResponse res = http.send(req)


Most values I've tried work, except for the empty string ('') and whitespace only (' ').

An HTTP client MUST use this header field when issuing a SOAP HTTP Request.

and

The presence and content of the SOAPAction header field can be used by servers such as firewalls to appropriately filter SOAP request messages in HTTP. The header field value of empty string ("") means that the intent of the SOAP message is provided by the HTTP Request-URI. No value means that there is no indication of the intent of the message.

So again, you need to define it. And in this case Salesforce doesn't use the value.

I figured out the problem and now im getting the session ID actually the mistake was in setting the action header initially i have setted Soap action as

req.setheader('SOAPAction',''); then i saw the wsdl where the SOAPACtion was like (SOAPAction,"") then tried as mentioned in wsdl req.setheader('SOAPAction','""'); and I got the output.

• I'm surprised that is needed but well done for figuring it out. – Keith C Jun 18 '14 at 14:34

I am not sure why you are being asked for the action header.

This Partner WSDL example:

<?xml version="1.0" encoding="utf-8" ?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>

• @ManojChandran Delete the line req.setHeader('SOAPAction',''); as the example posts no header not a header set to an empty string. – Keith C Jun 18 '14 at 12:38