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

Session ID to execute Apex Class

Using a C# receiver we currently are executing an Apex class using a user name and password. This is working as planned and the login code segment is below:
SForce.SforceService sfdc = new SForce.SforceService();
SForce.LoginResult lr = sfdc.login("", "passwordU6RQC66T6hpZTuaY960FX3QvS");

Instead of using user credentials, we'd like to execute the same Apex class with the Session id that is being passed in the outbound message. When we make the change to the code segment we are finding that the Apex class does not execute. The login code segment is below: 
String strSessionID = notifications1.SessionId;
SForce.LoginResult lr = new LoginResult();
lr.sessionId = strSessionID;
lr.serverUrl =;

Are there any omissions in the sesson id code segment (above) that would prevent us from executing the Apex class? Welcome the thoughts and comments.
your code is going to end up trying to make a soap call to /home/home.jsp, which isn't going to work. You should make it so that you're just setting the sessionHeader on the apex stub, and not changing the URL at all.
I am using following code getting error:

string userid = Session["Usrid"].ToString();
string password = Session["Uspasswd"].ToString();
LoginResult lr = sfdc.login(userid,password);

not getting error when its hardcoded
LoginResult lr = sfdc.login("", "zzzzzzzzzzzzzzzzzzzzz");
getting error:
UNKNOWN_EXCEPTION: Destination URL not reset. The URL returned from login must be set in the SforceService

how to fix this.

Message Edited by RajeevKumar on 12-10-2008 10:07 AM
I fixed this issue as following:

string user = Session["Usrid"].ToString();
string pass = Session["Uspasswd"].ToString();
LoginResult lr = sfdc.login(user.TrimEnd().TrimStart(), pass.TrimEnd().TrimStart());

Hi SimonF,

I did tried what you mentioned "just setting the sessionHeader on the apex stub, and not changing the URL at all."; but it did not work and my try/catch get no exceptions. Any working "HelloWorld" sample?

(I did my .NET Outbound receiver, strightly following the "OM Sample" [upon receiving a message, call an APEX class]; it works fine with using name/pws to log in, but not working swap to use SessionID.)



post your code, all you need to do is set the sessionId, as the custom apex WSDLs already have the correct serverUrl in them. If you didn't get any exceptions, how do you know its not working ?