示例#1
0
        public void Run()
        {
            try
            {
                //Get crm configuration from app.config
                ServerConfiguration config = new ServerConfiguration();
                config.GetServerConfiguration();

                //Init crm service
                using (var service = CrmServiceHelper.GetOrganizationServiceProxy(config))
                {
                    //Basic Query Expression
                    //RetrieveMultipleByQueryExpression(service);

                    //Query Expression with LinkEntity
                    //RetrieveMultipleByQueryExpressionWithLinkEntity(service);

                    // QueryExpression Paging with cookie
                    //RetrieveMultipleWithPaging(service);

                    //Retrieve Contacts with linq
                    //RetrieveMultipleWithLinq(service);

                    //Basic Query Example using fetchXml
                    //QueryWithFetchXml(service);

                    //Query using fetchxml with aggration and grouping
                    //QueryWithFetchXmlAggreationAndGrouping(service);
                }
            }
            catch (FaultException <OrganizationServiceFault> ex)
            {
                Console.WriteLine("OrganizationServiceFault Exception: " + ex.Message);
                if (ex.InnerException != null)
                {
                    Console.WriteLine("Inner Exception: " + ex.InnerException.Message);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: " + ex.Message);
            }
            finally
            {
                Console.WriteLine("The end");
                Console.ReadLine();
            }
        }
        public void Run()
        {
            try
            {
                //Get crm configuration from app.config
                ServerConfiguration config = new ServerConfiguration();
                config.GetServerConfiguration();

                //Init crm service
                var service = CrmServiceHelper.GetOrganizationServiceProxy(config);

                //Call who am I request
                SendWhoAmIRequest(service);

                //Create a new account
                //var accountEntityToCreate = PrepareAccountEntityToCreate();
                //var accountId = CreateEntity(service, accountEntityToCreate);

                //Retrieve
                //var entityRetrieved = RetrieveEntity(service, accountId, EntityName.Account, null);

                //Update
                //UpdateEntity(service, accountId, EntityName.Account);

                //Delete
                //DeleteEntity(service, accountId, EntityName.Account);

                //Define accountId
                var accountId = new Guid("605F2550-9C4B-E911-9664-00155DDF3D03");

                //Retrive an account and print all the attribute in string format
                //var entity = RetrieveEntity(service, accountId, EntityName.Account, null);
                //CrmDataHelper.PrintEntity(entity);
            }
            catch (FaultException <OrganizationServiceFault> ex)
            {
                Console.WriteLine("OrganizationServiceFault Exception: " + ex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: " + ex.Message);
            }
            finally
            {
                Console.WriteLine("The end");
                Console.ReadLine();
            }
        }
        private void BtnConnect_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var config  = GetServerConfiguration();
                var service = CrmServiceHelper.GetOrganizationServiceProxy(config);

                WhoAmIRequest request  = new WhoAmIRequest();
                var           response = (WhoAmIResponse)service.Execute(request);

                CrmConnectionSuccessful(response.UserId.ToString());
            }
            catch (FaultException <OrganizationServiceFault> ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }