WCF客户端消耗多个使用HTTP Cookie的asmx服务 [英] WCF client consuming multiple asmx service that uses HTTP Cookies

查看:159
本文介绍了WCF客户端消耗多个使用HTTP Cookie的asmx服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在多个WCF客户端端点使用相同的http cookie(实际上是一个asmx sessionid)。

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()< - 创建一个HTTP cookie,它是服务器ASP.NET sessionid

注销()< - 销毁相同的cookie

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

SomeOtherService.asmx

DoSomeThing()< - 从AuthenticationService.asmx重新生成一个有效的cookie。

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

如何共享HTTP Cookie多个端点。

How can I share the HTTP Cookie across multiple endpoints.

我无法控制服务器代码,必须使用WCF。

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

推荐答案

查看本文。解释了如何手动管理WCF客户端代理中的Cookie。更准确地说,WCF提供了一个API,可以从HTTP响应中提取Cookie,同样,也可以手动将Cookie设置为HTTP请求。

$
您将要做的是利用此机制可以从给定客户端代理接收的HTTP响应中手动提取Cookie,并将同一个Cookie分配给由另一个客户端代理发送给不同服务的HTTP请求。

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.

MSDN论坛上的此线程解释了如何通过使用WCF消息检查器对应用程序中的每个服务调用执行此操作。

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.

这篇关于WCF客户端消耗多个使用HTTP Cookie的asmx服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆