首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OperationContext.Current.SessionId获得空

OperationContext.Current.SessionId获得空
EN

Stack Overflow用户
提问于 2016-06-06 08:58:46
回答 2查看 1.2K关注 0票数 0

当我调用服务GetSessionId()时,会话id将获得空值。请帮我解决这个问题。

代码语言:javascript
复制
public Response<string> GetSessionId()
{
    Response<string> respn = new Response<string>();
    respn.Succeeded = false;

    try
    {
        _sessionId = OperationContext.Current.SessionId;
        respn.ReturnData = _sessionId;
        respn.Succeeded = true;
    }
    catch (Exception ex)
    {
        respn.Succeeded = false;
        respn.ErrorMsg = ex.Message;
    }
    return respn;
}

在Web.Config文件中,如果我设置为mode="Message“和clientCredentialType="Windows”,在这种情况下,它将得到会话id.But,我不能使用任何安全性。

代码语言:javascript
复制
<wsHttpBinding>
    <binding name="SOAPService_EndpointBinding"
             maxReceivedMessageSize="2147483647"
             openTimeout="00:02:00"
             closeTimeout="00:02:00"
             sendTimeout="24:00:00"
             receiveTimeout="24:00:00">          
      <security mode="None">
        <message clientCredentialType="None"/>
      </security>
    </binding>
  </wsHttpBinding>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-06-08 04:50:57

解决办法如下,

契约接口中的,将SessionMode属性设置为必需的

ServiceContract(SessionMode = SessionMode.Required)

在配置文件中启用了reliableSession

代码语言:javascript
复制
<wsHttpBinding>
    <binding name="SOAPService_EndpointBinding"
             maxReceivedMessageSize="2147483647"
             openTimeout="00:02:00"
             closeTimeout="00:02:00"
             sendTimeout="24:00:00"
             receiveTimeout="24:00:00">          
      <security mode="None">
        <message clientCredentialType="None"/>
      </security>
      <reliableSession enabled="true"/>
    </binding>
  </wsHttpBinding>
票数 0
EN

Stack Overflow用户

发布于 2016-06-07 09:26:44

您正在使用的绑定是什么?会话支持以下绑定

  • NetTcpBinding
  • NetNamedPipeBinding
  • WSHttpBinding (仅在打开安全性或可靠性的情况下)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37653299

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档