给出以下连接代码:
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();
如果提供的密码不正确,代码会弹出凭据对话框。 由于该服务无权与桌面交互,因此服务暂停,因为它实际上无法显示对话框。
如何取消对话框,并抛出异常。我正在使用动态2011。
答案 0 :(得分:1)
我会认为CRM动态OrganizationServiceProxy
是硬连线的,可以弹出一个对话框。
没有配置选项或标志可以关闭此行为。
答案 1 :(得分:0)
您可能混淆了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);
}