Skip to content

Instantly share code, notes, and snippets.

@steefjan
Created August 3, 2010 19:11
Show Gist options
  • Save steefjan/506949 to your computer and use it in GitHub Desktop.
Save steefjan/506949 to your computer and use it in GitHub Desktop.
[Serializable]
public static class ForceToken
{
private static DateTime _sessionDate = DateTime.Now;
private static string _sessionId = string.Empty;
public static string SessionId
{
get { return GetSession(); }
}
private static string GetSession()
{
DateTime now = DateTime.Now;
TimeSpan diff = now.Subtract(_sessionDate);
if (_sessionId == string.Empty || (diff.Minutes > 60))
{
//TODO lock object during update
//refresh token
System.Diagnostics.EventLog.WriteEntry("Utilities", "Salesforce.com Session Refresh");
string uname = "<sf account>";
string password = "<sf password>";
string securityToken = "<sf token>";
SFSvcRef.SforceService proxy = new SFSvcRef.SforceService();
proxy.Url = "https://www.salesforce.com/services/Soap/c/16.0";
SFSvcRef.LoginResult result = proxy.login(uname, password + securityToken);
_sessionId = result.sessionId;
}
return _sessionId;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment