function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
darrenw_ukdarrenw_uk 

INVALID_SESSION_ID + beginner's questions

Hi all

 

I've got a website which integrates with Salesforce using straightforward soql, but there are instances where this is quite cumbersome eg repeated round trips to recursively get account parent ids, until the top of the hierarchy is reached etc. For these sort of problems I thought an Apex web service woudl be ideal, as only one call would be required  and all the business logic could be hosted by SF.

 

My first step was to set up a free developer account and write a simple method to get a Lead by email address (using this as an example - http://www.devproconnections.com/article/aspnet2/force-com-for-asp-net-developers.aspx). I exported the wsdl from this account and and the enterprise wsdl from my production account and set up a test project which references both. I'm setting the sessionheader.session id to the sessionid yeilded by logging in via the enterprise wsdl, and then I get Invalid Session ID found in SessionHeader: Illegal Session. Session not found, missing session key: when calling my new method. However, the sessionid is populated and appears to be current as the website is working fine using this sessionid, making soql calls etc.

 

So firstly, is this the right way of approaching  this? Secondly, do you know why this error is occuring? Thirdly, if I can overcome this, will the web service have access to custom fields/objects in my production account, by virtue of the fact that I'm passing a valid sessionid from this account?

 

Hope that all makes sense! Any help/guidance much appreciated!

 

c#.net code below:

 

rootUsername = "xxxxxxxxxxxxxxxx";
            rootUserpw = "xxxxxxxxxxxxx";
            binding = new sfEnterprise.SforceService();
            sfEnterprise.LoginResult lr = binding.login(rootUsername, rootUserpw);
            binding.SessionHeaderValue = new sfEnterprise.SessionHeader();
            binding.SessionHeaderValue.sessionId = lr.sessionId;
            sessionExpires = DateTime.Now.Add(new TimeSpan(0, 0, 100, 0, 0));
            binding.Url = lr.serverUrl;

            getLeadInfo.getLeadInfoService glis = new getLeadInfo.getLeadInfoService();
            getLeadInfo.SessionHeader sessionHeader = new getLeadInfo.SessionHeader();
            sessionHeader.sessionId = lr.sessionId;

            glis.SessionHeaderValue = sessionHeader;

            getLeadInfo.Lead getLeadInfoResponse = new getLeadInfo.Lead();   //ERROR OCCURS HERE