driAn
driAn

Reputation: 3335

Make WCF call ClaimsAuthenticationManager.Authenticate only once per session

I setup a custom ClaimsAuthenticationManager for my wcf service. Now I found out that the method ClaimsAuthenticationManager.Authenticate is executed for each and every wcf call. Instead I want to have it executed once per session to avoid unneccessary overhead.

According to Microsoft:

The claims authentication manager is typically invoked once per session, with the following exceptions: For transport security, tokens present at the transport layer will invoke the claims authentication once per call, even if sessions are present.

Source: https://msdn.microsoft.com/en-us/library/ee748487.aspx

Since my custom binding does not use transport security I see no reason why ClaimsAuthenticationManager.Authenticate is executed per call.

Does anyone know if there are further requirements that need to be met to have this method called once per session instead? Thank you very much for any suggestions.

The wcf binding configuration:

<behaviors>
  <serviceBehaviors>
    <behavior name="defaultBehavior">
      <serviceDebug includeExceptionDetailInFaults="True" />
      <serviceThrottling maxConcurrentCalls="200" maxConcurrentSessions="200" maxConcurrentInstances="200" />
      <serviceCredentials useIdentityConfiguration="true" />
      <serviceAuthorization principalPermissionMode="Always" />
    </behavior>
  </serviceBehaviors>
</behaviors>

<bindings>
  <netNamedPipeBinding>
    <binding name="ServiceNamedPipeBinding" receiveTimeout="00:05:00" sendTimeout="00:05:00" maxReceivedMessageSize="134217728" maxBufferPoolSize="134217728" maxBufferSize="134217728" />
  </netNamedPipeBinding>
  <customBinding>
    <binding name="TcpLoadBalanced" receiveTimeout="00:05:00" sendTimeout="00:05:00">
      <security authenticationMode="SecureConversation" requireSecurityContextCancellation="true">
        <secureConversationBootstrap authenticationMode="SspiNegotiated"/>
      </security>
      <binaryMessageEncoding>
        <readerQuotas maxArrayLength="2147483647" />
      </binaryMessageEncoding>
      <tcpTransport listenBacklog="200" maxBufferPoolSize="134217728" maxReceivedMessageSize="134217728" maxBufferSize="134217728">
        <connectionPoolSettings leaseTimeout="00:00:00" maxOutboundConnectionsPerEndpoint="0" />
      </tcpTransport>
    </binding>
  </customBinding>
</bindings>

Upvotes: 0

Views: 397

Answers (1)

Rajat_RJT
Rajat_RJT

Reputation: 62

If you want to use per session call,then try like this-

[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerSession)]
public class MyService:IMyService
{
    public int MyMethod()
    {
        int m_Counter = 0;
        m_Counter++;
        return m_Counter;
    }       
}

Upvotes: 0

Related Questions