Hello there,
I am dealing with my session management code at the moment, and contemplating if I should force a logout.
My understanding is that because Betfair uses a REST api, we don't really need to logout. Hence probably why Joel didn't add that code in.
As an aside, here is some sample code to do a logout if anyone finds that interesting (I didn't author it)
string jsonData = null;
var responseText = string.Empty;
var endpoint = @"https://identitysso-cert.betfair.com/api/logout";
try {
System.Net.ServicePointManager.Expect100Continue = false;
var request = (HttpWebRequest)WebRequest.Create(endpoint);
request.Method = "POST";
request.Timeout = 5000;
request.ContentType = "application/json";
request.Accept = "application/json";
request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
request.KeepAlive = true;
request.Headers.Add("Accept-Encoding", "gzip, deflate");
if (Credentials.UseBetfairDelayedData)
request.Headers.Add("X-Application", Credentials.DelayedAppKey);
else
request.Headers.Add("X-Application", Credentials.LiveAppKey);
request.Headers.Add("X-Authentication", sessionToken);
if (string.IsNullOrEmpty(jsonData) == false) {
using (var streamWriter = new StreamWriter(request.GetRequestStream())) {
streamWriter.Write(jsonData);
}
}
using (var response = (HttpWebResponse)request.GetResponse()) {
using (var streamReader = new StreamReader(response.GetResponseStream())) {
responseText = streamReader.ReadToEnd();
}
}
}
catch (System.Exception e) {
Domain.Global.Logger.Log("Exception in Logout: " + e.Message + "\r");
return false;
}
What do you guys think?
Thanks for any thoughts.
I am dealing with my session management code at the moment, and contemplating if I should force a logout.
My understanding is that because Betfair uses a REST api, we don't really need to logout. Hence probably why Joel didn't add that code in.
As an aside, here is some sample code to do a logout if anyone finds that interesting (I didn't author it)
string jsonData = null;
var responseText = string.Empty;
var endpoint = @"https://identitysso-cert.betfair.com/api/logout";
try {
System.Net.ServicePointManager.Expect100Continue = false;
var request = (HttpWebRequest)WebRequest.Create(endpoint);
request.Method = "POST";
request.Timeout = 5000;
request.ContentType = "application/json";
request.Accept = "application/json";
request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
request.KeepAlive = true;
request.Headers.Add("Accept-Encoding", "gzip, deflate");
if (Credentials.UseBetfairDelayedData)
request.Headers.Add("X-Application", Credentials.DelayedAppKey);
else
request.Headers.Add("X-Application", Credentials.LiveAppKey);
request.Headers.Add("X-Authentication", sessionToken);
if (string.IsNullOrEmpty(jsonData) == false) {
using (var streamWriter = new StreamWriter(request.GetRequestStream())) {
streamWriter.Write(jsonData);
}
}
using (var response = (HttpWebResponse)request.GetResponse()) {
using (var streamReader = new StreamReader(response.GetResponseStream())) {
responseText = streamReader.ReadToEnd();
}
}
}
catch (System.Exception e) {
Domain.Global.Logger.Log("Exception in Logout: " + e.Message + "\r");
return false;
}
What do you guys think?
Thanks for any thoughts.


In the end I made mine do a keep alive every 1/4 of whatever my timeout period is. (I believe the default is 8 hours and you can change it in the security settings on the website). The other thing to note for anyone else reading here is that, any random call to the API will not refresh your time out period. You gotta do the keep alive.,
Comment