gpt4 book ai didi

c# - 使用 HTTPS 的 WCF session

转载 作者:太空狗 更新时间:2023-10-29 18:12:59 26 4
gpt4 key购买 nike

我不知道如何在使用 HTTPS 时为我的 WCF 服务启用每 session 实例。 (我不是 ASP.NET 专家,但如果可能我不想使用 ASP.NET session 状态。)我正在使用 .NET Framework 3.0。

我得出了下面的矛盾,希望有人能告诉我逻辑上哪里有漏洞。

1) 由于客户要求,服务必须托管在 IIS 6 上。

2) 服务需要在调用之间保持状态,包括 SqlConnection 和 SqlTransaction 实例(丑陋但由于项目限制是必要的)。

3) 因此我需要使用 wsHttpBinding。

4) 该服务需要能够从 HttpContext.Current.User.Identity 访问用户身份验证信息(例如,在 IIS 中使用 Windows 安全性)。

5) 因此需要 HTTPS。

6) 因此必须在绑定(bind)上配置传输级安全。

7) 将服务配置为需要 session 意味着我必须将 wsHttpBinding 配置为使用可靠 session 。

8) 这需要在绑定(bind)上配置消息级安全。

即(6) 和 (8) 是互斥的。

似乎使用 WCF session 要求我使用消息级安全性,这使我无法使用 HTTPS。

我错过了什么?

最佳答案

3) TruewsHttpBindingwsDualHttpBinding 是唯一支持 session 的 HTTP 绑定(bind)

5) 错误,为了对服务调用者进行身份验证,您不一定需要具有任何传输级别的安全性(例如 SSL/HTTPS)。唯一的要求是配置 IIS 以启用虚拟目录的集成 Windows 身份验证。然后在 WCF 中,您可以通过三种可能性来启用此方案:

a) 通过 Windows 凭据 (HTTPS) 在 wsHttpBinding 上使用传输级安全

<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="SecurityEnabledWsHttp">
<security mode="Transport">
<transport clientCredentialType="Windows" />
</security>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>

b) 通过 Windows 凭据 (HTTP) 在 wsHttpBinding 上使用消息级安全

<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="SecurityEnabledWsHttp">
<security mode="Message">
<message clientCredentialType="Windows" />
</security>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>

c) 在ASP.NET 兼容模式下运行您的服务,并在 ASP.NET (HTTP) 中启用Windows 身份验证

<system.web>
<authentication mode="Windows" />
</system.web>

请注意,在 ab 中,您将通过以下方式从服务中访问调用者的身份:

OperationContext.Current.ServiceSecurityContext.WindowsIdentity

6) 正确,必须在 wsHttpBinding 上启用传输级安全才能使用 HTTPS

7) False, Reliable Sessions 是 WCF session 的 Reliable Messaging 的特定实现。 Reliable Messaging 是一种 WS-* 标准规范,旨在保证在不可靠的网络上传递消息。您可以在没有 Reliable Messaging 的情况下使用 WCF session ,反之亦然。 session 在具有此属性的服务契约(Contract)上启用:

[ServiceContract(SessionMode=SessionMode.Required)]
public interface IMyService {
// ...
}

还要记住,为了在服务调用之间保持状态,您必须明确地在服务契约实现上启用适当的实例模式:

[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerSession)]
public class MyService : IMyService {
// ...
}

WCF 中有两种 session :安全 session 可靠 session wsHttpBindingnetTcpBinding 的默认设置是使用安全 session 。
对于 wsHttpBinding,这是通过消息级安全完成的使用客户端的凭据,这是绑定(bind)的默认设置
相反,对于 netTcpBinding, session 是通过使用TCP协议(protocol)。
这意味着只需切换到 wsHttpBinding 或 netTcpBinding 即可启用对 WCF session 的支持。
另一种方法是使用 Reliable Sessions。这必须在绑定(bind)配置中显式启用,并消除对 wsHttpBinding 使用消息安全性的要求。所以这会起作用:

<bindings> 
<wshttpbinding>
<binding name="ReliableSessionEnabled">
<reliablesession enabled="True" ordered="False" />
<security mode="None" />
</binding>
</wshttpbinding>
</bindings>

8) False,可靠 session 的使用独立于通信 channel 的安全设置。

有关更详细的解释,请查看 this article .

关于c# - 使用 HTTPS 的 WCF session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/427954/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com