Dynamics CRM 代码在服务中弹出对话框

Dynamics CRM code popping up dialog in service

给定以下连接代码:

    var serviceUri = "http://machine.co.za/CRM/XRMServices/2011/Organization.svc";

    var clientCredentials = new ClientCredentials
    {
        Windows =
        {
            ClientCredential = new System.Net.NetworkCredential("SOMEUSER", "SOMEPASS", "DOMAIN")
        }
    };
    var organizationServiceProxy = new OrganizationServiceProxy(new Uri(serviceUri), null, clientCredentials, null);
    // This line of code pops up a dialog?
    var user = (WhoAmIResponse)organizationServiceProxy.Execute(new WhoAmIRequest());
    if (user.UserId == Guid.Empty)
        throw new InvalidOperationException(string.Format(@"connection to {0} cannot be established.", crmConnection.ServiceUri));
    user.Dump();

如果提供的密码不正确,代码会弹出一个凭据对话框。 由于该服务没有与桌面交互的权限,因此服务会停止,因为它实际上无法显示对话框。

如何取消对话框,并改为抛出异常。我使用的是 Dynamics 2011.

您可能混淆了 CrmConnection 的用法。归结为:

var conn = new ConnectionStringSettings("CRM", "Url=http://machine.co.za/CRM; Username=SOMEUSER; Password=SOMEPASS; Domain=SOMEDOMAIN")
var crmConnection = new CrmConnection(conn);
var crmService = new OrganizationService(crmConnection);
try
{
    // connection will actually happen here. anything goes wrong, exceptions will be thrown
    var user = crmService.Execute<WhoAmIResponse>(new WhoAmIRequest());
    user.Dump();
} 
catch (Exception ex)
{
    // just a proof of concept
    // ex is of type MessageSecurityException if credentials are invalid
    throw new InvalidOperationException(string.Format(@"connection to {0} cannot be established.", crmConnection.ServiceUri), ex);
}

我假设 CRM 动态 OrganizationServiceProxy 是硬连接弹出对话框的。

没有配置选项或标志可以关闭此行为。