当前位置: 代码迷 >> Web Service >> 为啥 wcf 中 System.Web.HttpContext.Current.Session 总是为Null
  详细解决方案

为啥 wcf 中 System.Web.HttpContext.Current.Session 总是为Null

热度:492   发布时间:2016-05-02 02:20:53.0
为什么 wcf 中 System.Web.HttpContext.Current.Session 总是为Null
为什么 wcf 中 System.Web.HttpContext.Current.Session 总是为Null。网上说的各种节点配置都尝试过还是不行。下面直接贴 源码,各位大神们求解。
契约:

方法:


web.Config
	<system.serviceModel>

<bindings>

<wsHttpBinding>
<binding name="WSHttpBinding_ICCFlowServer" maxReceivedMessageSize="8388608"  maxBufferPoolSize="524288" allowCookies="true"
       closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" >
<reliableSession enabled="true"/>
<readerQuotas maxStringContentLength="8388608"/>
<security  mode="None">
<!--此属性控制安全上下文令牌是否通过客户端与服务之间的 WS-SecureConversation 交换建立。将它设置为 true 要求远程方支持 WS-SecureConversation。-->
<message establishSecurityContext="true"/>

</security>

</binding>
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="CCFlowServer" name="flowSDKWcf.ServerFun.CCFlowServer">
<endpoint  address="" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ICCFlowServer" contract="flowSDKWcf.ServiceContract.ICCFlowServer" />
</service>
</services>

<behaviors>
<serviceBehaviors>
<behavior name="CCFlowServer">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

</system.serviceModel>

客户端调用:

CCFlowServerClient flowclient = new CCFlowServerClient();
                    flowclient.SetCookie();
                    string s = flowclient.GetCooie();

客户端 config
	<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_ICCFlowServer">
<reliableSession enabled="true" />
<security mode="None">
<!--<transport clientCredentialType="Windows" />
<message clientCredentialType="Windows" />-->
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8088/ServerFun/CCFlowServer.svc"
 binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ICCFlowServer"
 contract="CCWorkFlowServer.ICCFlowServer" name="WSHttpBinding_ICCFlowServer" />
</client>
</system.serviceModel>


返回回来的s 都是 "null of sessions"

哪里配置不对或者代码有问题 还望大神们指点啊
------解决方案--------------------
WCF中实例模式(InstanceContextMode)与会话模式(SessionMode)
  相关解决方案