简体   繁体   中英

OperationContext.Current.SessionId getting null

When I calling to the service GetSessionId(), session id getting null value. Please help me to solve this problem..

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;
}

In Web.Config file if I set to security mode="Message" and clientCredentialType="Windows" in that case it will get the session id.But I cannot use any security.

<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>

What is the binding that you are using? Session is supported with the following binding

  • NetTcpBinding
  • NetNamedPipeBinding
  • WSHttpBinding (only if security or reliability is turned on)

The Solution is as follows,

In the contract interface, have SessionMode attribute set to Required

[ServiceContract(SessionMode = SessionMode.Required)]

Enabled reliableSession to true in the configuration file

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM