Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何通过会话保护WCF服务?_Wcf_Web Services_Security_Authentication - Fatal编程技术网

如何通过会话保护WCF服务?

如何通过会话保护WCF服务?,wcf,web-services,security,authentication,Wcf,Web Services,Security,Authentication,我的自白:我是WCF的新手,我读过一些关于它的东西,但我刚刚接触到它不到一个星期 我想通过会话保护我的WCF,这与网页一样,首先客户端需要识别自己,但当它经过身份验证时,WCF服务会信任它,直到会话超时 因为服务是时间关键型的,所以安全机制应该尽可能少 如上所述,我没有使用WCF的经验,所以我不知道我的想法是否可行,以及WCF广泛使用哪些机制 非常感谢。最佳做法是使用无会话服务,因为引入会话会导致其他复杂性 在您的情况下,可以使用WS-SecureConversation、WS-Trust等提供

我的自白:我是WCF的新手,我读过一些关于它的东西,但我刚刚接触到它不到一个星期

我想通过会话保护我的WCF,这与网页一样,首先客户端需要识别自己,但当它经过身份验证时,WCF服务会信任它,直到会话超时

因为服务是时间关键型的,所以安全机制应该尽可能少

如上所述,我没有使用WCF的经验,所以我不知道我的想法是否可行,以及WCF广泛使用哪些机制


非常感谢。

最佳做法是使用无会话服务,因为引入会话会导致其他复杂性

在您的情况下,可以使用WS-SecureConversation、WS-Trust等提供的安全会话(安全上下文)保护SOAP服务。在使用任何类型的WCF会话时,必须重用相同的服务代理实例。会话存在于特定代理和服务实例之间。一旦其中任何一个失效或连接出现错误,会话就会消失,您必须打开一个新的代理

使用安全对话时,您将在服务代理中填写所需的凭据并运行通信。代理将向服务发送这些凭据,服务将创建一个用于后续通信的安全令牌。这种初始握手有一些额外的成本。以下通信由令牌保护。WCF将其与消息级加密和签名结合使用,这会带来额外的成本。您可以关闭某些消息部分的加密和签名,但至少必须加密与身份验证相关的信息

此类服务的基本配置如下所示:

<bindings>
  <wsHttpBinding>
    <binding name="secured">
      <security mode="Message">
        <message clientCredentialType="UserName" estabilishSecurityContext="true"
                 negotiateServiceCredentials="false" />
      </security>
    </binding>      
  </wsHttpBinding>
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="securedService">
      ...
      <serviceCredentials>
        <!-- Allows configuring how user name and password will be validated -->
        <userNameAuthentication ... />
        <!-- Message security with user name and password credentials requires service certificate -->
        <serviceCertificate ... />
      </serviceCredentials>
    </behavior>
  </serviceBehaviors>
</behaviors>
<services>
  <service name="..." behaviorConfiguration="securedService">
    <endpoint address="" contract="..." binding="wsHttpBinding" 
              bindingConfiguration="secured" />
  </service>
</services>

...
这是在WCF中执行此操作的标准方法,安全性集成到WCF安全管道中。其他方法主要是绕过WCF安全管道或修改安全管道——这两种方法都需要大量定制开发