WCF 客户端使用多个使用 HTTP Cookie 的 asmx 服务

发布于 2024-07-07 09:39:46 字数 404 浏览 11 评论 0原文

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

服务器有多个端点,其中之一是:

AuthenticationService.asmx
Login() <- 创建一个 HTTP cookie,它是服务器 ASP.NET sessionid
Logout() <- 销毁相同的 cookies

SomeOtherService.asmx
DoSomeThing() <- 从 AuthenticationService.asmx 请求有效的 cookie。

如何在多个端点之间共享 HTTP Cookie。

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

葬心 2024-07-14 09:39:46

请查看这篇文章 .
它解释了如何在 WCF 客户端代理中手动管理 cookie。 更准确地说,WCF 公开了一个 API,让您可以从 HTTP 响应中提取 cookie,并以同样的方式手动为 HTTP 请求设置 cookie。

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

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

更新:

我写了一篇关于如何解决此问题的博客文章。 您可以在此处阅读。

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.

习ぎ惯性依靠 2024-07-14 09:39:46

如果启用了 asp.net 兼容模式,则可以从 WCF 服务中访问 http 会话,因此不需要添加任何 cookie 来执行此操作。

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

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

好菇凉咱不稀罕他 2024-07-14 09:39:46

我刚刚遇到了同样的问题。 如果 WCF 客户端仅与一个 ASP.NET 服务通信,那么这很容易。 只需将 BasicHttpBinding 上的 AllowCookies 属性设置为 true,服务代理就会自动处理 ASP.NET 会话 ID cookie。

但我遇到了像您这样的情况,我需要 WCF 客户端与 2 个 ASP.NET 服务进行通信。 第一个发出 ASP.NET 会话 ID cookie,我需要能够在对第二个服务的调用中传递该 cookie。 有谁知道如何做到这一点?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文