+ Start a Discussion
PauloPaulo 

Invalid_Session_ID: Invalid Session ID found in SessionHeader

I think I'm on the right track to creating a lead but I get a "Invalid_Session_ID" error when I try to add the lead. Code is posted below. Am I missing something or what am I doing wrong?

private void createLead() {

//Create the proxy binding and login

sforce.SforceService binding = new sforce.SforceService();

try {

sforce.LoginResult lr = binding.login("login", "pwd");

Session.Add("sessionId", lr.sessionId);

Session.Add("url", lr.serverUrl);

Session.Add("userId", lr.userId);

sforce.Lead lead = new sforce.Lead();

}

catch (Exception ex) {

lblException.Text = ex.Message;

}

binding.Url = Session["url"].ToString();

// Create an account object to send to the service

Credco.Web.SignUp.sforce.Lead sfLead = new Credco.Web.SignUp.sforce.Lead();

// Set several properties

sfLead.FirstName = "Paulo";

sfLead.LastName = "Morales";

sfLead.LeadSource = "Testing";

// Add the account to an array of SObjects

sforce.sObject[] records = new sforce.sObject[] {sfLead};

// Invoke the create call, passing in the account properties

// and saving the results in a SaveResult object

sforce.SaveResult[] saveResults = binding.create(records);

// Access the new ID

String newID = saveResults[0].id;

}

SuperfellSuperfell
You need to set the returned sessionId into the Soap Session header before you call create.

binding.SessionHeaderValue = new sforce.SessionHeader();
binding.SessionHeaderValue.SessionId = (string)Session["sessionId"]
PauloPaulo
That worked thanks. But it didn't add the lead to salesforce. Am I still missing something to do an insert into salesforce?