用户会话服务(User session service)和其他系统服务一样随AOS自动安装,提供两个主要的服务操作:GetUserSessionInfo()和GetAccessRights()。GetUserSessionInfo返回调用用户的默认信息,包括语言、公司、币种、时区等信息,这些信息保存在AX用户的Options及其公司的设置中。GetAccessRights返回对指定对象的用户权限,这些对象包括菜单项、表、表字段、Web菜单项。
还是用个例子来演示如何使用用户会话服务,从URL地址http://<servername>:8101/DynamicsAx/Services/UserSessionService添加用户会话服务的服务引用:
var client = new UserSessionServiceClient(); // Call the User Session service var userSessionInfo = client.GetUserSessionInfo(null); Console.WriteLine("AOS Locale: " + userSessionInfo.AOSLocaleName); Console.WriteLine("Language: " + userSessionInfo.AXLanguage); Console.WriteLine("Default Company: " + userSessionInfo.Company); Console.WriteLine("Company Time Zone: " + userSessionInfo.CompanyTimeZone); Console.WriteLine("Default Currency: " + userSessionInfo.CurrencyInfo.CurrencyCode); Console.WriteLine("UserID:" + userSessionInfo.UserId); Console.WriteLine("Preferred Calendar: " + userSessionInfo.UserPreferredCalendar); Console.WriteLine("Preferred Time Zone: " + userSessionInfo.UserPreferredTimeZone); var rights = client.GetAccessRights(null, new[]{ new AccessControlledItemKey{ItemType = AccessControlledType.Table, ItemName = "CustTable"}, new AccessControlledItemKey{ItemType = AccessControlledType.MenuItemDisplay,ItemName = "CustTableDetails"} }); Console.WriteLine("Permission of table CustTable:" + rights[0]); Console.WriteLine("Permission of menu item CustTableDetails:" + rights[1]);
演示代码先后调用了两个服务操作,显示会话用户的默认信息,返回会话用户对表CustTable和菜单项CustTableDetails拥有的最高权限(Delete、Edit等)。
本文是AIF系列文章的最后一篇,以此结束AX 2012 AIF的学习。