Пример #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)
            {
            }
        }
Пример #3
0
        static async Task Main(string[] args)
        {
            try
            {
                var _crmUrl           = "https://crm.test.ru/";
                var _organizationName = "Org";
                var config            = Microsoft.Xrm.Sdk.Client.ServiceConfigurationFactory
                                        .CreateConfiguration <Microsoft.Xrm.Sdk.IOrganizationService>(
                    new Uri($"{_crmUrl}{_organizationName}/XRMServices/2011/Organization.svc"));


                var clientCredentials = new System.ServiceModel.Description.ClientCredentials();
                clientCredentials.Windows.ClientCredential.UserName = "******";
                clientCredentials.Windows.ClientCredential.Password = "******";

                var client = new Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy(config, clientCredentials);
                //client.CallerId = new Guid("5c073647-da06-e611-80f9-005056971789");

                var q = new Microsoft.Xrm.Sdk.Query.QueryExpression("role")
                {
                    ColumnSet = { Columns = { "name", "businessunitid", "roleid" } },
                    Orders    =
                    {
                        new Microsoft.Xrm.Sdk.Query.OrderExpression("name", Microsoft.Xrm.Sdk.Query.OrderType.Ascending)
                    },
                    LinkEntities =
                    {
                        new Microsoft.Xrm.Sdk.Query.LinkEntity("role",                                              "systemuserroles", "roleid",       "roleid",
                                                               Microsoft.Xrm.Sdk.Query.JoinOperator.Inner)
                        {
                            LinkEntities =
                            {
                                new Microsoft.Xrm.Sdk.Query.LinkEntity("systemuserroles",                           "systemuser",                           "systemuserid",
                                                                       "systemuserid",                              Microsoft.Xrm.Sdk.Query.JoinOperator.Inner)
                                {
                                    LinkCriteria =
                                    {
                                        Filters            =
                                        {
                                            new Microsoft.Xrm.Sdk.Query.FilterExpression(Microsoft.Xrm.Sdk.Query
                                                                                         .LogicalOperator.And)
                                            {
                                                Conditions =
                                                {
                                                    new Microsoft.Xrm.Sdk.Query.ConditionExpression("systemuserid",
                                                                                                    Microsoft.Xrm.Sdk.Query.ConditionOperator.EqualUserId)
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                };

                var rq = new Microsoft.Xrm.Sdk.Messages.RetrieveMultipleRequest()
                {
                    Query = q
                };

                /*var n = new Microsoft.Crm.Sdk.Messages.SetStateRequest
                 * {
                 *  EntityMoniker =
                 *      new Microsoft.Xrm.Sdk.EntityReference("lead", new Guid("c5dc1b6f-1712-e811-8229-005056977311")),
                 *  State = new Microsoft.Xrm.Sdk.OptionSetValue(0),
                 *  Status = new Microsoft.Xrm.Sdk.OptionSetValue(100000003)
                 * };
                 *
                 * var r = client.Execute(n);*/

                var result = await client.RetrieveMultiple(q);

                //return result.Entities.Select(i => i.GetAttributeValue<string>("name"));
                foreach (var role in result.Entities)
                {
                    Console.WriteLine(role.GetAttributeValue <string>("name"));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            Console.WriteLine();
            Console.WriteLine("Press key");
            Console.ReadKey();
        }