+ Start a Discussion
David Zhu 8David Zhu 8 

Get Salesforce VF Page 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);
            }





 
David Zhu 8David Zhu 8
actually, I an not getting error message. The VF page returning content is not as expected. Instead, it returns a general failure content (shown above)