C# – WCF client consuming multiple asmx service that uses HTTP Cookies

asmxasp.netccookieswcf

I am trying to use the same http cookie (in effect a asmx sessionid), in multiple WCF client endpoints.

The server has several endpoints, one of them is:

AuthenticationService.asmx
Login() <- Creates a HTTP cookie that is the servers ASP.NET sessionid
Logout() <- Destroys the same cookies

SomeOtherService.asmx
DoSomeThing() <- Requeres a valid cookie from the AuthenticationService.asmx.

How can I share the HTTP Cookie across multiple endpoints.

I dont have control over the server code, and the must use WCF.

Best Answer

Have a look at this article.
It explains how to manually manage cookies in a WCF client proxy. More precisely WCF exposes an API to let you extract cookies from an HTTP response, and in the same way, manually set a cookie to an HTTP Request.

What you will have to do is leveraging this mechanism to manually extract a cookie from the HTTP response received by a given client proxy, and assign that same cookie to the HTTP request sent by another client proxy to a different service.

This thread on the MSDN Forums explains how to do this for every service call in an application by using WCF Message Inspectors.

UPDATE:

I've written a blog post about how to solve this issue. You can read it over here.

Related Topic