为什么每次在wsHttpBinding中创建新的会话ID

时间:2014-10-31 18:27:54

标签: wcf session wshttpbinding wcf-wshttpbinding

我正在使用以下配置来使我的服务会话,但对于每个请求,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>

1 个答案:

答案 0 :(得分:0)

默认情况下,会话会在频道开启时启动,您可以在此Sessions in WCF

中阅读更多相关信息。

如果IsInitiating参数的默认值为true,则每个调用都会启动一个新会话。在此处详细了解IsInitiatingIsInitiating

所以在你的运营合同中

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