2

Am new to integration ,and can code in APex. I have written a apex class exposed as webservice to call. As i understand : to get an inbound call to salesforce - this apex codes wsdl needs to shared with external application.

ALso, while doing this found WSDL was quite absurd -had lot of info that required. So I have to modify my wsdl as there were lot of unwanted entities which was not part of my apex code. is there any alternative way of getting rid of unwanted entities?

Post manually modifying wsdl I tested it using SOAP UI,but it keeps getting the invalid session ID error.

Am not sure-- how to resolve this error? I dont have answers to my below queries:

  • In SOAP UI-- how can we pass a session ID?
  • How can I test this by removing session ID and using client certificate?

Error: INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session<

2

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.

  • Thanks Daniel ,but am not sure how to start. -- Do i have to write a seperate login class for my inbound request for account creation? – user10727 Feb 17 '15 at 10:55
  • ALso: i tried Enterprise WSDL testing using SOAP UI : for login Request : I gave the username and password as i use to login to application...but it keeps failing with invalid login.. Login History shows my attempt. Login Type : Networks Portal API Only and status : Invalid login. Am not getting how does it accept this...Same credential works with APex dataloader – user10727 Feb 17 '15 at 10:57
  • I used SOAP UI : and got this working- can see the records getting created using API request. Now i want to know the way you have explained: So do i have write a another class which would give me this Login information and session id and then pass onto my class for sObject Operation.? – user10727 Feb 17 '15 at 13:08
  • You will need to use one of several ways outlined in the answer to get a valid Salesforce session id. How you do this will entirely depend on what the integrating application is. In most cases one of the OAuth flows is the best option. While less secure, you could also just do a login() API call via either the Enterprise or Partner APIs. – Daniel Ballinger Feb 17 '15 at 23:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.