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

Vik*_*ram 14 wcf

当我SessionMode = SessionMode.Required在servicecontract中使用时,我得到这个错误

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

有谁告诉我一个解决方案?

Ben*_*Ben 10

随着它的上市在这里,选择wsHttpBindingNetTcpBinding.WSHttpBinding结合.


小智 10

此错误消息很少清除.答案是这样的,basichttpbinding不支持会话.因此,如果要使用它,则必须使用以下属性.[ServiceContract(SessionMode = SessionMode.Allowed)]

这意味着,如果您尝试配置多个绑定,如basichttp,wshttp,net.tcp,WCF将自动启用除basichttp绑定之外的会话.因此,如果您使用SessionMode.Required而不是Allowed,那么您将被迫不使用basichttpbinding.

也就是说,解决这个问题通常需要这样的事情:

<system.serviceModel>
    <protocolMapping>
      <add scheme="http" binding="wsHttpBinding" bindingConfiguration="wsHttpBindingConfiguration" />
    </protocolMapping>
    <bindings>
      <wsHttpBinding>
        <binding name="wsHttpBindingConfiguration" transactionFlow="true" />
      </wsHttpBinding>
      .......
Run Code Online (Sandbox Code Playgroud)