3) 只有 True, wsHttpBinding, 和 wsDualHttpBinding 这三种 HTTP 绑定支持会话。
5) False,为了认证服务调用者,您不一定需要任何传输级别的安全性(如 SSL/HTTPS)。唯一的要求是在虚拟目录中配置 IIS 以启用 Integrated Windows Authentication。然后在 WCF 中,您有三种可能的选择来启用此方案:
a) 使用传输级别安全性,在 wsHttpBinding 上使用 Windows 凭据(HTTPS)
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="SecurityEnabledWsHttp">
<security mode="Transport">
<transport clientCredentialType="Windows" />
</security>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
b) 在使用基于 HTTP 的 wsHttpBinding 时,使用基于消息的安全性和 Windows 凭据。
<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身份验证,同时开启ASP.NET兼容性模式
<system.web>
<authentication mode="Windows" />
</system.web>
请注意,在 a 和 b 中,您可以通过以下方式从服务中访问调用者的标识:
OperationContext.Current.ServiceSecurityContext.WindowsIdentity
6) True, 必须在wsHttpBinding中启用传输级别安全性才能使用HTTPS。
7) False, 可靠会话(Reliable Sessions) 是 WCF 会话的一种特定实现,而可靠消息(Reliable Messaging) 则是一个针对不稳定网络设计的 WS-* 标准规范,旨在保证消息传递的可靠性。您可以在没有可靠消息时使用WCF会话,反之亦然。服务契约中使用此属性启用会话:
[ServiceContract(SessionMode=SessionMode.Required)]
public interface IMyService {
}
同时请记住,为了在服务调用之间保持状态,您需要明确在服务合同实现上启用适当的实例模式:
[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerSession)]
public class MyService : IMyService {
}
WCF分为两种会话类型:安全会话和可靠会话。对于wsHttpBinding和netTcpBinding,默认设置是使用安全会话。
对于wsHttpBinding,这是通过使用客户端凭据的消息级安全来实现的,这是绑定的默认设置。
相反,对于netTcpBinding,会话是通过使用TCP协议的设施在传输级别上建立的。
这意味着简单地切换到wsHttpBinding或netTcpBinding将启用对WCF会话的支持。
另一种选择是使用可靠会话。这必须在绑定配置中显式启用,并删除了在wsHttpBinding中使用消息安全的要求。因此,以下内容将工作:
<bindings>
<wshttpbinding>
<binding name="ReliableSessionEnabled">
<reliablesession enabled="True" ordered="False" />
<security mode="None" />
</binding>
</wshttpbinding>
</bindings>
8) False, 可靠会话(Reliable Sessions)与通信渠道的安全机制是独立使用的。
想要更详细的解释,请查看这篇文章。