wcf - 契约(Contract)需要 Session,但 Binding 'BasicHttpBinding' 不支持它或未正确配置以支持它

标签 wcf

当我使用 SessionMode = SessionMode.Required在 servicecontract 然后我得到这个错误

Contract requires Session, but Binding 'BasicHttpBinding' doesn't support it or isn't configured properly to support it.



有人告诉我一个解决方案吗?

最佳答案

此错误消息很少清楚。这里的答案是这样的,basichttpbinding 不支持 session 。所以如果你想使用它,你必须使用下面的属性。
[ServiceContract(SessionMode = SessionMode.Allowed)]

这意味着,如果您尝试配置多个绑定(bind),如 basichttp、wshttp、net.tcp,WCF 将自动为 basichttp 绑定(bind)以外的 session 启用 session 。因此,如果您使用 SessionMode.Required 而不是 Allowed,那么您将被迫不使用 basichttpbinding。

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

<system.serviceModel>
    <protocolMapping>
      <add scheme="http" binding="wsHttpBinding" bindingConfiguration="wsHttpBindingConfiguration" />
    </protocolMapping>
    <bindings>
      <wsHttpBinding>
        <binding name="wsHttpBindingConfiguration" transactionFlow="true" />
      </wsHttpBinding>
      .......

关于wcf - 契约(Contract)需要 Session,但 Binding 'BasicHttpBinding' 不支持它或未正确配置以支持它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4406972/

相关文章:

c# - WCF 调用者未通过 WsDualHttpBinding 中的服务进行身份验证

c# - 如何在 .NET 中自定义 JSON 枚举的反序列化?

带有 WCF Web 服务的 C# 传统服务器

c# - 在 WCF 中将异常作为响应的一部分传递

c# - WCF设计原则: Is it a good idea to edit auto-generated proxy classes?

wpf - WCF和WPF有什么区别?

c# - 您需要 c# 才能使用 wcf-soap 吗?

wcf - 已超出传入消息的最大消息大小配额 (65536)

c# - WCF 服务不喜欢单引号

c# - 具有 Entity Framework 的 WCF 存储库服务模式