0

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>
Cœur
  • 37,241
  • 25
  • 195
  • 267
Neo
  • 1
  • 4
  • IIRC the session ID is not about "security", but about session enabled binding. See [here](http://stackoverflow.com/a/6122908/21567) for a possible answer. – Christian.K Jun 06 '16 at 10:53
  • Problem has been solved, I added and ServiceContract set to SessionMode.Required. – Neo Jun 08 '16 at 04:24

2 Answers2

0

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)
  • I'm using WSHttpBinding. Problem has been solved, I added and ServiceContract set to SessionMode.Required. – Neo Jun 08 '16 at 04:24
0

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>
Neo
  • 1
  • 4