C# Client - Clean way to synthesize session

For some of our back end batch processes we’d like to use a c# client but have not been able to figure out how to synthesize the session data that is typically returned from GetSession.

Many of our implementations do this:

    var sess = GetSession() as UserSession;
    var results = QueryWithContext(SomeORMObject, sess.AccountIdentifier);
    return results;

Is there a way to populate a C# client’s session programmatically without doing post to Auth?

If you have got client authenticated you can save ss-id and ss-pid cookies somewhere and then add these saved cookie values to newly created clients. ISeviceClient has two extension methods SetSessionId(string sessionId) for setting “ss-id” cookie and SetPermanentSessionId(string sessionId) for setting “ss-pid” cookie. You can save session cookies by using opposite methods: GetSessionId and GetPermanentSessionId.

Also if you use token authentication you might be interested to look at GetTokenCookie and SetTokenCookie extension methods of IServiceClient.

Of course, to reuse this cookies and reconstruct client programmatically you must be authenticated on the server and have the valid session for these cookies on server.