You will need to get an active Salesforce session id and know which instance it comes from. You can do this in a number of ways, such as:
- using one of the oauth flows (generally the preferred method),
- by calling login on the partner/enterprise API,
- via a canvas app (signed request),
- or just copying the id from the current sid cookie.
Once you have it, you will need to send that value in the SessionHeader.
For example, take the web service:
global class TimeWebService {
webService static string getTime() {
return DateTime.now().formatLong();
}
}
Just for demonstration purposes, I generated the Apex classes to call it. Invoking it with anonymous Apex:
soapSforceComSchemasClassDfbTimeweb.TimeWebService ts = new soapSforceComSchemasClassDfbTimeweb.TimeWebService();
ts.SessionHeader = new soapSforceComSchemasClassDfbTimeweb.SessionHeader_element();
ts.SessionHeader.sessionId = UserInfo.getSessionId();
String serverTime = ts.getTime();
System.debug(serverTime);
Note here that the Session Id was taken directly from the active Salesforce Session and that the web services endpoint default to that from the WSDL. In my case: https://na5.salesforce.com/services/Soap/class/DFB/TimeWebService
. In an external application you will need to determine the SessionId and instance(na5) components via other means.
The XML Soap Request was:
<?xml version="1.0" encoding="utf-8"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Header>
<SessionHeader xmlns="http://soap.sforce.com/schemas/class/DFB/TimeWebService">
<sessionId>00D700000000001!AQoAQHvUJOLpAbU1d_NOTAREALSESSIONID_KlHXaMdj</sessionId>
</SessionHeader>
</env:Header>
<env:Body>
<getTime xmlns="http://soap.sforce.com/schemas/class/DFB/TimeWebService" />
</env:Body>
</env:Envelope>
Note the env:Header
containing the SessionHeader and sessionId.