1

Why does XrmServiceContext return empty set, when there is no activity for around 6 hours?

    public ServiceAppointment GetServiceActivity(Guid serviceActivityGuid)
    {
        return _xrmServiceContext.ServiceAppointmentSet.FirstOrDefault(x => x.Id == serviceActivityGuid);
    }

If I start my application, and execute the method above, it will return good data; however, if I start the application and then wait approximately 6 hours, it will return an empty set.

How can I adjust the authentication timeout? (Please note that my assumption about this being a timeout may not be true).

Alex Gordon
  • 57,446
  • 287
  • 670
  • 1,062
  • How are you newing up the context? and how are you waiting for 6 hours after newing up before calling `GetServiceActivity`? – dynamicallyCRM Jan 23 '17 at 20:17
  • it's newing up once at the application start, i'm using RestSharp to manage the session – Alex Gordon Jan 23 '17 at 21:08
  • `OrganizationServiceContext` which `XrmServiceContext` expects as a constructor parameter, is a wcf wrapper. I wonder if the context is GCed. Any reason as to why the object is only newed up on `Application_Start` and not per request? Ideally the life time should be per http request. – dynamicallyCRM Jan 23 '17 at 21:24

1 Answers1

1

You'll need to handle the token refresh in your code. If it is expired, you'll need to reauthenticate to get a new token. Here is an example - it is for an iOS app but you should be able to use the same code for your app.

https://jlattimer.blogspot.com/2015/04/crm-mobile-helper-code-refresh-tokens.html

Josh Painter
  • 4,071
  • 21
  • 26