我为我的wcf服务设置了自定义ClaimsAuthenticationManager。现在我发现每个wcf调用都执行了ClaimsAuthenticationManager.Authenticate方法。相反,我希望每次会话执行一次,以避免不必要的开销。
根据微软的说法:
声明身份验证管理器通常在每个会话中调用一次,但以下情况除外:对于传输安全性,传输层中的令牌将在每次调用时调用声明身份验证一次,即使会话存在也是如此
来源:https://msdn.microsoft.com/en-us/library/ee748487.aspx
由于我的自定义绑定不使用传输安全性,我认为没有理由为每次调用执行ClaimsAuthenticationManager.Authenticate。
有没有人知道是否需要满足进一步的要求才能让每个会话调用一次此方法?非常感谢您的任何建议。
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>
答案 0 :(得分:0)
如果您想使用每次会话,请尝试这样 -
[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerSession)]
public class MyService:IMyService
{
public int MyMethod()
{
int m_Counter = 0;
m_Counter++;
return m_Counter;
}
}