AzMan API 在高负载下返回无效数据
我有一个调用授权管理器 (AzMan) API 的 WCF 服务 - 这是一个 COM 接口。我使用以下代码来获取给定用户帐户的角色列表:
public string[] GetRoleNamesForUser(string appName, SecurityIdentifier userSID)
{
m_azManStore.UpdateCache(null);
IAzApplication app = GetApplication(appName);
List<string> userRoles = new List<string>();
if (userSID != null)
{
IAzClientContext context = app.InitializeClientContextFromStringSid(userSID.ToString(), 1, null);
object[] roles = (object[])context.GetRoles("");
foreach (string uRole in roles)
{
userRoles.Add(uRole);
}
Marshal.FinalReleaseComObject(context);
}
return userRoles.ToArray();
}
此代码在大多数情况下工作正常。但是,在负载测试时(始终使用相同的 userSID),此代码有时会返回角色列表的空数组。 AzMan 是否有重负载问题,或者我对 AzMan COM 对象或其他东西没有做正确的事情?
I have a WCF service that calls the Authorization manager (AzMan) API - which is a COM interface. I use the following code to get a list of roles for a given user account:
public string[] GetRoleNamesForUser(string appName, SecurityIdentifier userSID)
{
m_azManStore.UpdateCache(null);
IAzApplication app = GetApplication(appName);
List<string> userRoles = new List<string>();
if (userSID != null)
{
IAzClientContext context = app.InitializeClientContextFromStringSid(userSID.ToString(), 1, null);
object[] roles = (object[])context.GetRoles("");
foreach (string uRole in roles)
{
userRoles.Add(uRole);
}
Marshal.FinalReleaseComObject(context);
}
return userRoles.ToArray();
}
This code works fine most of the time. However, while load testing (always using the same userSID), this code will sometimes return an empty array for the list of roles. Does AzMan have a problem with heavy load or is there something I am not doing right with regaurd to the AzMan COM object or something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 AzMan COM 对象时,必须使用
Marshal.FinalReleaseCOMObject(object)
来释放资源。如果不这样做,可能会发生内存泄漏。我必须将 AzMan 存储包装在一次性类中,以便每次调用都会打开 AzMan,使用它然后关闭它。结果是应用程序速度较慢,但更稳定。看看这个SO问题了解更多详细信息
When using the AzMan COM object you must use
Marshal.FinalReleaseCOMObject(object)
to release resources. A memory leak is possible if this is not done. I had to wrap the AzMan store in a disposable class so that each call would open AzMan, use it then close it. The result is a slower, but more stable, application.Take a look at this SO question for more details