[英]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.