WCF client consuming multiple asmx service that uses HTTP Cookies

与世无争的帅哥 提交于 2019-12-05 02:10:19

问题


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.


回答1:


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.




回答2:


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




回答3:


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?



来源:https://stackoverflow.com/questions/201153/wcf-client-consuming-multiple-asmx-service-that-uses-http-cookies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!