I'm currently working on a client to connect to an API which is a facade for several SOAP service endpoints. I am using .Net Core 3.1
The SOAP service was written by other company and cannot be changed. We have multiple services, and each one has "login" method. After succesfull login, session cookie is returned in headers. Cookie needs to be appended to every subsequent calls to access other methods.
To achieve this, we have written middleware, which suppose to catch response from login method, and store the cookie. Then it should alter requests to WCF service, adding the cookie to headers.
Unfortunately, the middleware is triggered only, when our API path is called, not when SOAP service calls are made. Lets say im calling path "/test" in my API. The middeware is raised properly and executes. Aftehr that, my code behind is executed making SOAP service calls, and unfortunately the middleware isnt triggered.
I've looked into many topics, such as THIS or THIS
but we want to be able to globally alter messages instead of explicitly add cookie "manualy" when making every single call. Also, when session expired, we want to catch this situation and login again, without user noticing. This is why its so importat to write middleware class.
So i have my conneted services (proxies generated using Microsoft WCS Web Service Reference Provider), called like this:
MyServiceClient client = new MyServiceClient();
var logged = await client.loginAsync(new loginRequest("login", "password"));
if (logged.@return) {
//doing stuff here (getting cookie, storing in places)
}
The loginAsync method response has cookie in its headers. How can we register some sort of middleware or interceptor to get response and extract the cookie from this method?
Than, we have service call:
var data = await client.getSchedule(new getScheduleRequest(DateTime.Parse("2020-06-01"), DateTime.Parse("2020-06-23")));
And now i want my message inspector/middleware/interceptor to alter the request and add stored cookie as header.
Middleware is registered in Startup.cs:
app.UseMiddleware<WCFSessionMiddleware>();
I've also tried using behaviors, but the problem is the same - it needs to be called every time i create wcf service client to alter the behaviour using:
client.Endpoint.EndpointBehaviors.Add(myBehaviour);
I would appriciate any help, no matter how small.
