Reputation: 16002
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.
Upvotes: 0
Views: 115
Reputation: 16002
I am going to take it as a given that the CRM dynamics OrganizationServiceProxy
is hardwired to pop up a dialog.
There are no configuration options or flags that turn this behavior off.
Upvotes: 1
Reputation: 23300
You may be mixing up usage of 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);
}
Upvotes: 0