简体   繁体   English

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

[英]Dynamics CRM code popping up dialog in service

Given the following connection code: 给定以下连接代码:

    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();

If the supplied password is incorrect, the code pops up a credentials dialog. 如果提供的密码不正确,则代码将弹出一个凭证对话框。 Since the service does not have rights to interact with the desktop, the service halts as it cannot actually show a dialog. 由于该服务无权与桌面进行交互,因此该服务暂停,因为它实际上无法显示对话框。

How do I suppress the dialog, and have an exception get thrown instead. 我如何抑制对话框,而是抛出异常。 I am using dynamics 2011. 我正在使用动力学2011。

弹出的对话框!

I am going to take it as a given that the CRM dynamics OrganizationServiceProxy is hardwired to pop up a dialog. 我将以CRM动态OrganizationServiceProxy代理硬性弹出对话框为例。

There are no configuration options or flags that turn this behavior off. 没有配置选项或标志可以关闭此行为。

You may be mixing up usage of CrmConnection . 您可能会混淆CrmConnection用法。 It boils down to: 归结为:

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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM