views:

2549

answers:

3

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.

A: 

If you enabled asp.net compatibility mode, you can access the http session from within your WCF service, so you shouldn't need to add any cookies to do this.

http://msdn.microsoft.com/en-us/library/ms752234.aspx

jezell
The problem is that I havent created the asmx service, it is out of my control.I do have control over the client, but as far as I can tell ASP.Comp mode is for server endpoint services?
Yes, it just has to be enabled in the web.config for the site.
jezell
A: 

I just ran into the same problem. If the WCF client is only talking to one ASP.NET service then it's easy. Just set the AllowCookies property on the BasicHttpBinding to true and the service proxy will automatically handle the ASP.NET session ID cookie.

But I've got a situation like yours where there are 2 ASP.NET services I need my WCF client to talk to. The first one issues an ASP.NET session ID cookie, and I need to be able to pass that cookie in calls to the second service. Does anyone know how to do this?

I've written a blog post about how to solve this issue:http://megakemp.wordpress.com/2009/02/06/managing-shared-cookies-in-wcf/
Enrico Campidoglio
+3  A: 

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.

Enrico Campidoglio