使用 HTTPS 的 WCF 会话
我无法弄清楚如何在使用 HTTPS 时为我的 WCF 服务启用每会话实例。 (我不是 ASP.NET 专家,但如果可能的话,不想使用 ASP.NET 会话状态。)我正在使用 .NET Framework 3.0。
我遇到了以下矛盾,希望有人能告诉我哪里有逻辑缺陷。
1) 由于客户要求,该服务必须托管在 IIS 6 上。
2)服务需要维护调用之间的状态,包括SqlConnection和SqlTransaction实例(虽然丑陋但由于项目限制是必要的)。
3)因此我需要使用wsHttpBinding。
4) 该服务需要能够从HttpContext.Current.User.Identity 访问用户身份验证信息(例如,在IIS 中使用Windows 安全性)。
5) 因此需要HTTPS。
6) 因此必须在绑定上配置传输级安全性。
7) 将服务配置为需要会话意味着我必须将 wsHttpBinding 配置为使用可靠会话。
8) 这需要在绑定上配置消息级安全性。
即(6)和(8)是互斥的。
看来使用 WCF 会话需要我使用消息级安全性,这会阻止我使用 HTTPS。
我缺少什么?
I cannot figure out how to enable per-session instances for my WCF service while using HTTPS. (I'm not an ASP.NET expert but don't want to use ASP.NET session state if possible.) I am using .NET Framework 3.0.
I have arrived at the following contradiction and am hoping that someone can tell me where there is a flaw in the logic.
1) The service must be hosted on IIS 6 due to client mandate.
2) The service needs to maintain state between calls, including SqlConnection and SqlTransaction instances (ugly but necessary due to project constraints).
3) Therefore I need to use the wsHttpBinding.
4) The service needs to be able to access user authentication info from HttpContext.Current.User.Identity (e.g. using Windows security in IIS).
5) HTTPS is therefore required.
6) Transport-level security must therefore be configured on the binding.
7) Configuring the service to require sessions means I have to configure the wsHttpBinding to use Reliable Sessions.
8) This requires that message-level security is configured on the binding.
I.e. (6) and (8) are mutually exclusive.
It seems that using WCF sessions requires that I use message-level security, which prevents me from using HTTPS.
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
3) True、wsHttpBinding 和 wsDualHttpBinding 是唯一支持会话的 HTTP 绑定
5) False,以便对服务调用者进行身份验证,您不一定需要任何传输级安全性(例如 SSL/HTTPS)。 唯一的要求是将 IIS 配置为为虚拟目录启用集成 Windows 身份验证。 然后,在 WCF 中,您可以通过三种方式实现此方案:
a) 在带有 Windows 凭据 (HTTPS) 的 wsHttpBinding 上使用传输级安全性
b) 在带有 Windows 凭据 (HTTP) 的 wsHttpBinding 上使用消息级安全性
c) 在以下环境下运行您的服务ASP.NET 兼容模式 并在 ASP.NET (HTTP) 中启用 Windows 身份验证
请注意,在 a 和 b 中> 您将通过以下方式从服务中访问调用者的身份:
6) True,必须在 wsHttpBinding 上启用传输级安全才能使用 HTTPS
7) False、可靠会话是 WCF 会话的可靠消息传递的特定实现。 可靠消息传递是一种 WS-* 标准规范,旨在保证不可靠网络上的消息传递。 您可以在没有可靠消息传递的情况下使用 WCF 会话,反之亦然。 使用此属性在服务契约上启用会话:
还请记住,为了维护服务调用之间的状态,您必须明确地在服务契约实现上启用适当的实例模式:
WCF 中有两种会话:安全会话和可靠会话。 wsHttpBinding 和 netTcpBinding 的默认设置都是使用安全会话。
对于 wsHttpBinding,这是通过使用消息级安全来完成的客户端的凭据,这是绑定的默认设置。
对于 netTcpBinding,会话是通过使用 TCP 协议的设施在传输级别建立的.
这意味着只需切换到 wsHttpBinding 或 netTcpBinding 即可启用对 WCF 会话的支持。
另一种方法是使用可靠会话。 这必须在绑定配置中显式启用,并且消除了对 wsHttpBinding 使用消息安全性的要求。 因此,这将起作用:
8) False,可靠会话的使用独立于通信通道的安全设置。
有关更详细的说明,请查看此文章。
3) True, wsHttpBinding and wsDualHttpBinding are the only HTTP bindings that support sessions
5) False, in order to authenticate the service callers you don't necessarily need to have any transport-level security (such as SSL/HTTPS). The only requirement is to configure IIS to enable Integrated Windows Authentication for a virtual directory. Then in WCF you have three possibilities to enable this scenario:
a) Use transport-level security on the wsHttpBinding with Windows credentials (HTTPS)
b) Use message-level security on the wsHttpBinding with Windows credentials (HTTP)
c) Run your service under the ASP.NET Compatibility Mode and enable Windows Authentication in ASP.NET (HTTP)
Note that in a and b you will access the identity of the caller from within a service this way:
6) True, transport-level security must be enabled on the wsHttpBinding in order to use HTTPS
7) False, Reliable Sessions is a particular implementation of Reliable Messaging for WCF sessions. Reliable Messaging is a WS-* standard specification designed to guarantee message delivery on an unreliable network. You can use WCF sessions without Reliable Messaging, and viceversa. Sessions are enabled on the service contract with this attribute:
Also remember that in order to maintain state between service calls you will explicitly have to enable the appropriate instance mode on the service contract implementation:
There are two kinds of sessions in WCF: Secure Sessions and Reliable Sessions. The default setting for both wsHttpBinding and netTcpBinding is to use Secure Sessions.
For wsHttpBinding this is accomplished with message-level security by using the client's credentials, which is the default setting for the binding.
For netTcpBinding instead, the session is established at the tranport level by using the facilities of the TCP protocol.
This means that simply switching to wsHttpBinding or netTcpBinding will enable support for WCF sessions.
The alternative is to use Reliable Sessions. This has to explicitly be enabled in the binding configuration, and removes the requirement of using message security for the wsHttpBinding. So this will work:
8) False, Reliable Sessions are used independently of the security settings of the communication channel.
For a more detailed explanation, have a look at this article.
遵循 Enrico 的出色回答,这些是我正在使用的配置:
服务:
客户端:
注意:尽管如此,仍然没有使其与 Windows 身份验证一起使用。
Following through on Enrico's excellent answer, these are the configs I am using:
Service:
Client:
Note: still haven't gotten this to work with Windows authentication though.