Session info lost when calling Gateway.SendAsync()


I’m a few steps down the track from my last problem!

So I have a message in my MQ calling an authenticated service using IBearerHasToken like my issue a couple of days ago - all working great with 8.2.3.

Inside that handler, I want to call another internal service, and am using Gateway.SendAsync() to try and do that. However, I appear to be losing the session info along the way somehow.

Just before I call Gateway.SendAsync, Request.GetSession() returns the info I would expect.

When the request gets to the called service, Request.GetSession() does not return any of the expected info (in fact, it just has a session ID and created time).

Stepping through the code, I can see that by the time the InProcessServiceGateway constructor is called, it can no longer access that extra info from the Session, such as the authenticated username, etc.

Is that expected, or should I still be able to access the session?

Calling the service using base.ResolveService and then service.Post() works fine with the session info preserved.

Only the messages/aka Request DTOs are sent in Service Gateways, specify what you want to send on the Request DTO you’re sending. E.g. since it’s internal you should only need to the User Id to identify the user.

Fair enough, although I guess it is then unpredictable what info is available in a Service. I may stick to using ResolveService and calling it that way, unless you’re planning on deprecating that in the future.

ResolveService will call the Service Method in the same HTTP Request thread so it will share the same HTTP Request Context.

When you’re sending a message through a Service Gateway you shouldn’t be relying on any particular gateway implementation or external state like needing to be executed within the same HTTP Request context, so you should encapsulate what you want sent in the message itself.