我有一个自定义 mvc 应用程序,我想将其用作 crm 2011 的一部分(例如,我在 crm 面板上有一个按钮,它在我的 mvc 应用程序中调用操作)
我可以获取登录 crm 并按下按钮的用户凭据吗?
我使用此代码来运行组织服务。但是 WhoAmIRequest 返回 system 或 null(取决于 web.config 中的模拟属性)
var organizationUri = new Uri(Configuration.OrganizationUri());
var credentials = new ClientCredentials();
credentials.Windows.ClientCredential = (DefaultCredentials != null) ? DefaultCredentials : CredentialCache.DefaultNetworkCredentials;
IServiceConfiguration<IOrganizationService> orgConfigInfo = ServiceConfigurationFactory.CreateConfiguration<IOrganizationService>(organizationUri);
var service = new OrganizationServiceProxy(orgConfigInfo, credentials);
WhoAmIResponse response = (WhoAmIResponse)service.Execute(new WhoAmIRequest());
service.CallerId = response.UserId;