在 C# 控制台应用程序 (Dynamics CRM) 中获取 SystemUser 的用户名
Getting the username of SystemUser in a C# console application (Dynamics CRM)
有没有办法在常规 C# 控制台应用程序中获取用户名(或全名或 SystemUser 的任何内容)?
如果我执行 WhoAmIRequest,然后使用 UserId 从 OrganizationService 中检索 "SystemUserEntity",它会说没有名称为 'SystemUser' 的实体。
如果我尝试使用该 UserId 向 OData REST 端点发出 GET 请求(例如:http://localhost:8081/TestOrg/XRMServices/2011/OrganizationData.svc/SystemUserSet(guid'58a30c1a-3730-e511-80c8-080027c078bd'),我一直收到 401 forbidden,尽管如果我只是将 link 粘贴到我的浏览器中,我会得到我需要的所有信息。据我了解,那是因为我在使用浏览器时进行了身份验证。
所以,另一个可能的问题是 "how to get correct authentification in a C# Console Application to talk to the OData REST endpoint"。
获得用户 ID 后检索全名的工作方式如下:
// guid userId = ...
var username = service.Retrieve("systemuser", userId, new ColumnSet("fullname")).GetAttributeValue<string>("fullname");
请注意,您必须使用逻辑名称(全部小写)而不是模式(大写)名称,即 systemuser
而不是 SystemUser
有没有办法在常规 C# 控制台应用程序中获取用户名(或全名或 SystemUser 的任何内容)?
如果我执行 WhoAmIRequest,然后使用 UserId 从 OrganizationService 中检索 "SystemUserEntity",它会说没有名称为 'SystemUser' 的实体。
如果我尝试使用该 UserId 向 OData REST 端点发出 GET 请求(例如:http://localhost:8081/TestOrg/XRMServices/2011/OrganizationData.svc/SystemUserSet(guid'58a30c1a-3730-e511-80c8-080027c078bd'),我一直收到 401 forbidden,尽管如果我只是将 link 粘贴到我的浏览器中,我会得到我需要的所有信息。据我了解,那是因为我在使用浏览器时进行了身份验证。
所以,另一个可能的问题是 "how to get correct authentification in a C# Console Application to talk to the OData REST endpoint"。
获得用户 ID 后检索全名的工作方式如下:
// guid userId = ...
var username = service.Retrieve("systemuser", userId, new ColumnSet("fullname")).GetAttributeValue<string>("fullname");
请注意,您必须使用逻辑名称(全部小写)而不是模式(大写)名称,即 systemuser
而不是 SystemUser