If you’re writing Windows Forms or WPF application that needs to connect to a number of Dynamics CRM organizations on ad-hoc basis, e.g. custom tool, then try using ConnectionDialog class instead of home-grown connection code. It is very surprising how little attention receive CRM Developers Extensions in general and a little obscure but very handy ConnectionDialog class, in particular. With the help of this class (that has even its own “dedicated” namespace Microsoft.Xrm.Client.Windows.Controls.ConnectionDialog), the usually verbose boilerplate connection code can be reduced to the following:
ConnectionDialog cd = new ConnectionDialog();
bool? connected = cd.ShowDialog();
if (connected.GetValueOrDefault(false))
{
using (OrganizationService service =
new OrganizationService(
CrmConnection.Parse(cd.ConnectionString)))
{
// use CRM organization service
WhoAmIResponse response =
service.Execute(
new WhoAmIRequest());
}
}
of the