​string /userName = \"xxx@xxx.com.full\"; string password = \"xxxxxxxFbrTKKU8nrvr00Aq3TG9\"; SFDCPartner.SforceService SfdcBinding = null; SFDCPartner.LoginResult CurrentLoginResult = null; SfdcBinding = new SFDCPartner.SforceService(); try { CurrentLoginResult = SfdcBinding.login(userName, password); SfdcBinding.SessionHeaderValue = new SFDCPartner.SessionHeader(); SfdcBinding.SessionHeaderValue.sessionId = CurrentLoginResult.sessionId; SfdcBinding.Url = CurrentLoginResult.serverUrl; var request = (HttpWebRequest)WebRequest.Create(\"https://cs20.salesforce.com/apex/promopage\"); var postData = \"promo={\\\"Type\\\":\\\"TestMethod\\\",\\\"UserName\\\":\\\"4991431\\\",\\\"Password\\\":\\\"123\\\",\\\"Program\\\":\\\"Test\\\"}\"; var data = Encoding.ASCII.GetBytes(postData); request.Method = \"POST\"; request.ContentType = \"application/x-www-form-urlencoded\"; request.ContentLength = data.Length; request.Headers.Add(\"Authorization\", \"Bearer \" + CurrentLoginResult.sessionId); //request.Headers.Add(\"SESSIONID\", CurrentLoginResult.sessionId); using (var stream = request.GetRequestStream()) { stream.Write(data, 0, data.Length); } HttpWebResponse response = (HttpWebResponse)request.GetResponse(); System.IO.Stream data1 = response.GetResponseStream(); string html = String.Empty; using (StreamReader sr = new StreamReader(data1)) { html = sr.ReadToEnd(); } } catch (Exception e) { // This is something else, probably comminication SfdcBinding = null; throw (e); }", "answerCount": 2, "upvoteCount": 0, "datePublished": "2017-04-04T21:05:23.000Z", "author": { "@type": "Person", "name": "David Zhu", "url": "https://trailblazers.salesforce.com/profileView?u=0053A00000CMEI1QAP", "affiliation": { "@type": "Organization", "name": "--" } }, "suggestedAnswer": [ { "@type": "Answer", "text": "Did you solve it? I got a similar problem", "upvoteCount": 0, "url": "https://trailhead.salesforce.com/trailblazer-community/feed/0D54V00007T4Xj0SAF", "datePublished": "2023-12-06T17:46:17.000Z", "author": { "@type": "Person", "name": "Chani Zimerman (Lerner)", "url": "https://trailblazers.salesforce.com/profileView?u=0054S0000023KPzQAM", "affiliation": { "@type": "Organization", "name": "TechUnity" } } } ] } }
Skip to main content

I am using Partner WSDL and C⌗ to connect to Salesforce. Login has no issue.

After login, I am trying to access a VF Page and get the content but no luck. I am keeping getting this error.

I believe it is the sessionID was not passed properly. What could be wrong? My code is attached.

Thanks,

David

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">

<script>

if (this.SfdcApp && this.SfdcApp.projectOneNavigator) { SfdcApp.projectOneNavigator.handleRedirect('https://test.salesforce.com/?ec=302&startURL=%2Fvisualforce%2Fsession%3Furl%3Dhttps%253A%252F%252Fc.cs20.visual.force.com%252Fapex%252Fpromopage'); } else

if (window.location.replace){

window.location.replace('https://test.salesforce.com/?ec=302&startURL=%2Fvisualforce%2Fsession%3Furl%3Dhttps%253A%252F%252Fc.cs20.visual.force.com%252Fapex%252Fpromopage');

} else {;

window.location.href ='https://test.salesforce.com/?ec=302&startURL=%2Fvisualforce%2Fsession%3Furl%3Dhttps%253A%252F%252Fc.cs20.visual.force.com%252Fapex%252Fpromopage';

}

</script>

</head>

</html>

<!-- Body events -->

<script type="text/javascript">function bodyOnLoad(){if(window.PreferenceBits){window.PreferenceBits.prototype.csrfToken="null";};}function bodyOnBeforeUnload(){}function bodyOnFocus(){}function bodyOnUnload(){}</script>

</body>

</html>

<!--

...................................................................................................

...................................................................................................

...................................................................................................

...................................................................................................

-->

 

​string /userName = "xxx@xxx.com.full";

string password = "xxxxxxxFbrTKKU8nrvr00Aq3TG9";

SFDCPartner.SforceService SfdcBinding = null;

SFDCPartner.LoginResult CurrentLoginResult = null;

SfdcBinding = new SFDCPartner.SforceService();

try

{

CurrentLoginResult = SfdcBinding.login(userName, password);

SfdcBinding.SessionHeaderValue = new SFDCPartner.SessionHeader();

SfdcBinding.SessionHeaderValue.sessionId = CurrentLoginResult.sessionId;

SfdcBinding.Url = CurrentLoginResult.serverUrl;

var request = (HttpWebRequest)WebRequest.Create("https://cs20.salesforce.com/apex/promopage");

var postData = "promo={\"Type\":\"TestMethod\",\"UserName\":\"4991431\",\"Password\":\"123\",\"Program\":\"Test\"}";

var data = Encoding.ASCII.GetBytes(postData);

request.Method = "POST";

request.ContentType = "application/x-www-form-urlencoded";

request.ContentLength = data.Length;

request.Headers.Add("Authorization", "Bearer " + CurrentLoginResult.sessionId);

//request.Headers.Add("SESSIONID", CurrentLoginResult.sessionId);

using (var stream = request.GetRequestStream())

{

stream.Write(data, 0, data.Length);

}

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

System.IO.Stream data1 = response.GetResponseStream();

string html = String.Empty;

using (StreamReader sr = new StreamReader(data1))

{

html = sr.ReadToEnd();

}

}

catch (Exception e)

{

// This is something else, probably comminication

SfdcBinding = null;

throw (e);

}

 
2 answers
0/9000