Created
August 3, 2010 19:11
-
-
Save steefjan/506949 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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