【问题标题】:Why Creating new session id every time in wsHttpBinding为什么每次在 wsHttpBinding 中创建新的会话 id
【发布时间】:2014-10-31 18:27:53
【问题描述】:

我正在使用以下配置使我的服务具有会话性,但是对于每个请求,wcf 服务都会以新的会话 ID 响应我。为什么会这样,我需要让它为该客户端会话,以便每个请求都应该有相同的会话 id

<system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="wsHttp">
          <readerQuotas maxStringContentLength="10240" />
          <reliableSession enabled="true" />          
        </binding>
      </wsHttpBinding>
    </bindings>
    <services>                  
      <service name="wcfservice.serviceclass" behaviorConfiguration="MyFileServiceBehavior">

        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:51/"/>
            <add baseAddress="net.tcp://localhost:52/"/>
          </baseAddresses>          
        </host>
        <endpoint address="pqr" binding="wsHttpBinding" bindingConfiguration="wsHttp"
          name="b" contract="wcfservice.Iservice" />
        <endpoint address="pqr" binding="netTcpBinding" 
          name="c" contract="wcfservice.Iservice" />      
      </service>
    </services>   
    <behaviors>
      <serviceBehaviors>
        <behavior name="MyFileServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />              
        </behavior>
      </serviceBehaviors>
    </behaviors>

  </system.serviceModel>

【问题讨论】:

  • 您的 ServiceContractAttribute 上有 SessionMode = SessionMode.Required 吗?
  • 是 sessionmode.allowed
  • 将会话模式设置为必需,所以当出现问题时会抛出异常,修复所有内容后,您可以将其更改回允许。在您的问题中添加以下信息、调用您的服务的客户端示例代码、网络配置、任何物理负载平衡机制、防火墙(基于硬件和软件的模型)和代理服务器。

标签: wcf session wshttpbinding wcf-wshttpbinding


【解决方案1】:

默认情况下,当频道打开时会启动会话,您可以在此Sessions in WCF 中阅读更多信息

因为 IsInitiating 参数的默认值为 true,您的每个调用都会启动一个新会话。在这里阅读更多关于它IsInitiatingIsInitiating

所以在您的运营合同中

[OperationContract(
    IsInitiating=false,
    IsTerminating=false
  )]
  public void MethodOne()
  {
    return;
  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-23
    • 1970-01-01
    • 2014-09-02
    • 1970-01-01
    • 1970-01-01
    • 2014-04-25
    • 2012-01-19
    • 2014-01-15
    相关资源
    最近更新 更多