简体   繁体   English

使WCF调用ClaimsAuthenticationManager.Authenticate每个会话只一次

[英]Make WCF call ClaimsAuthenticationManager.Authenticate only once per session

I setup a custom ClaimsAuthenticationManager for my wcf service. 我为我的wcf服务设置了自定义ClaimsAuthenticationManager。 Now I found out that the method ClaimsAuthenticationManager.Authenticate is executed for each and every wcf call. 现在我发现每个wcf调用都执行了ClaimsAuthenticationManager.Authenticate方法。 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 资料来源: 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. 由于我的自定义绑定不使用传输安全性,因此我认为没有理由为每次调用执行ClaimsAuthenticationManager.Authenticate。

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: wcf绑定配置:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在ClaimsAuthenticationManager.Authenticate中处理错误 - How to Handle Errors during ClaimsAuthenticationManager.Authenticate 模拟:只调用一次或每次调用 MVC2 callng -&gt; WCF - Impersonation: call only once or keep calling per cient call MVC2 callng -> WCF WCF ClaimsAuthenticationManager中的依赖项注入 - Dependency Injection in WCF ClaimsAuthenticationManager WCF中每个呼叫的NHibernate会话-如何回滚 - NHibernate Session per Call in WCF - How to Rollback WCF:在这种情况下,每次通话或每次会话效果更好? - WCF: better per call o per session in this sceneario? 验证WCF中的每个调用 - Authenticate every call in WCF 验证对WCF服务的呼叫 - Authenticate a call to a WCF service WCF:Per-Call和Per-Session服务......需要说服Per-Call是值得的 - WCF: Per-Call and Per-Session services…need convincing that Per-Call is worthwhile 自WCF发布以来,WCF的默认实例管理模式是否从Per Call更改为Per Session? - Did the default instance management mode for WCF change from Per Call to Per Session since WCF's release? 为什么WCF限制我们每台机器仅打开一个命名管道一次? - Why does WCF Restrict us to Only Open a Named Pipe Once per Machine?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM