Пример #1
0
        public bool ProbarConexionCRM()
        {
            Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy        _serviceProxy;
            Microsoft.Xrm.Sdk.IOrganizationService                   _service;
            Microsoft.Crm.Sdk.Samples.ServerConnection.Configuration serverConfig;

            try
            {
                Microsoft.Crm.Sdk.Samples.ServerConnection serverConnect = new Microsoft.Crm.Sdk.Samples.ServerConnection();
                serverConfig = serverConnect.GetServerConfiguration();

                // Connect to the CRM web service using a connection string.
                using (_serviceProxy = new Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy(serverConfig.OrganizationUri, serverConfig.HomeRealmUri, serverConfig.Credentials, serverConfig.DeviceCredentials))
                {
                    _service = (Microsoft.Xrm.Sdk.IOrganizationService)_serviceProxy;
                    return(true);
                }
            }
            // Catch any service fault exceptions that Microsoft Dynamics CRM throws.
            catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> )
            {
                // You can handle an exception here or pass it back to the calling method.
                throw;
            }
            catch (Exception)
            {
                return(false);
            }
        }
Пример #2
0
        private static void ConexionCRM()
        {
            Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy        _serviceProxy;
            Microsoft.Xrm.Sdk.IOrganizationService                   _service;
            Microsoft.Crm.Sdk.Samples.ServerConnection.Configuration serverConfig;

            try
            {
                Microsoft.Crm.Sdk.Samples.ServerConnection serverConnect = new Microsoft.Crm.Sdk.Samples.ServerConnection();
                serverConfig = serverConnect.GetServerConfiguration();

                CrmServiceClient crmSvc = new CrmServiceClient(new System.Net.NetworkCredential("<UserName>", "<Password>", “ <Domain> ”), AuthenticationType.AD, "<Server>", "<Port>", "<OrgName>", useUniqueInstance: false, useSsl: false, <orgDetail>);

                // Connect to the CRM web service using a connection string.
                using (_serviceProxy = new Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy(serverConfig.OrganizationUri, serverConfig.HomeRealmUri, serverConfig.Credentials, serverConfig.DeviceCredentials))
                {
                    _service = (Microsoft.Xrm.Sdk.IOrganizationService)_serviceProxy;
                    var i = 0;
                }
            }
            // Catch any service fault exceptions that Microsoft Dynamics CRM throws.
            catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> )
            {
                // You can handle an exception here or pass it back to the calling method.
                throw;
            }
            catch (Exception)
            {
            }
        }