如何使用wsHttpBidning和仅传输安全性启用WCF会话

Mub*_*har 6 .net wcf wshttpbinding wcf-security wcf-sessions

我目前使用basicHttpBindings和SSL启用了WCF服务.但现在我需要启用wcf会话(而不是asp会话)所以我将服务转移到wsHttpBidnings但是会话未启用

我已经设定

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
Run Code Online (Sandbox Code Playgroud)

但是当我设定的时候

SessionMode=SessionMode.Required
Run Code Online (Sandbox Code Playgroud)

在服务合同上,它说

合同需要Session,但Binding'WSHttpBinding'不支持它,或者没有正确配置以支持它.

以下是WSHttpBinding的定义

<wsHttpBinding>
    <binding name="wsHttpBinding">
      <readerQuotas maxStringContentLength="10240" />
      <reliableSession enabled="false" />
      <security mode="Transport">
        <transport clientCredentialType="None">
          <extendedProtectionPolicy policyEnforcement="Never" />
        </transport>
      </security>
    </binding>
  </wsHttpBinding>
Run Code Online (Sandbox Code Playgroud)

请在这件事上给予我帮助

mar*_*c_s 7

如果您想要与wsHttpBinding"会话",则必须使用可靠的消息传递或安全会话.

要在wsHttpBinding上启用会话,您需要可靠的消息传递,为此,您需要更改可靠会话的设置(看起来像这样的标记<reliableSession/>) - 因此您的新配置将如下所示:

<wsHttpBinding>
    <binding name="wsHttpBinding">
      <readerQuotas maxStringContentLength="10240" />
      <reliableSession enabled="true" />
      <security mode="Transport">
        <transport clientCredentialType="None">
          <extendedProtectionPolicy policyEnforcement="Never" />
        </transport>
      </security>
    </binding>
  </wsHttpBinding>
Run Code Online (Sandbox Code Playgroud)

  • 这个答案是不正确的.可靠会话(<reliableSession enabled ="true"/>)不能与SSL一起使用(<security mode ="Transport"/>). (7认同)