Exemplo n.º 1
0
        /*METHOD TO CONNECT WITH CRM,RETRIEVE & UPDATE DATA.
         * RETRIEVE DATA VIA LINQ QUERY
         * PASSING EMAIL/CONTACT ID TO UPDATE CRM RECORD
         */
        private void Academic(string email, Guid Retrieved, String connectionString, bool promptforDelete)
        {
            //string connStr = ConfigurationManager.ConnectionStrings[0].ConnectionString;

            CrmServiceClient conn = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connectionString);

            {
                //Guid contactID;


                BUCKSdev svcContext = new BUCKSdev();

                var contacts = from c in svcContext.ContactSet
                               where c.ContactId == RetrievedContactID
                               select c;

                foreach (var contact in contacts)
                {
                    Contact updateContact = new Contact
                    {
                        ContactId     = RetrievedContactID,
                        EMailAddress1 = email
                    };

                    //_serviceProxy.Update(updateContact);
                    Console.WriteLine("Academic {0} updated", RetrievedContactID);
                }
            }
        }
Exemplo n.º 2
0
        private static IOrganizationService CreateOrganizationService()
        {
            string connectionString = ConfigurationManager.AppSettings["CRMConnectionString"].ToString();

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            CrmServiceClient conection = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connectionString);

            if (!conection.IsReady)
            {
                throw new Exception(conection.LastCrmError);
            }

            IOrganizationService service;

            if (conection.OrganizationWebProxyClient == null)
            {
                service = (IOrganizationService)conection.OrganizationServiceProxy;
            }
            else
            {
                service = (IOrganizationService)conection.OrganizationWebProxyClient;
            }

            return(service);
        }
Exemplo n.º 3
0
        protected IOrganizationService GetOrgService()
        {
            var connection = ConfigurationManager.ConnectionStrings[ConnectionStringName];

            // In case of missing connection string in configuration,
            // use ConnectionStringName as an explicit connection string
            var connectionString = connection == null ? ConnectionStringName : connection.ConnectionString;

            if (string.IsNullOrWhiteSpace(connectionString))
            {
                throw new Exception("The ConnectionStringName property must be either a connection string or a connection string name");
            }

#if (FAKE_XRM_EASY_2016 || FAKE_XRM_EASY_365 || FAKE_XRM_EASY_9) && !FAKE_XRM_EASY_DOTNETCORE
            // Connect to the CRM web service using a connection string.
            CrmServiceClient client = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connectionString);
            return(client);
#elif FAKE_XRM_EASY_DOTNETCORE
            var client = new Microsoft.PowerPlatform.Dataverse.Client.ServiceClient(connectionString);
            return(client);
#else
            CrmConnection       crmConnection = CrmConnection.Parse(connectionString);
            OrganizationService service       = new OrganizationService(crmConnection);
            return(service);
#endif
        }
Exemplo n.º 4
0
        public CrmService()
        {
            const string crmServerUrl = "https://demianraskosandbox.crm4.dynamics.com";
            const string userName     = "******";
            const string password     = "******";

            var connectionStringCrmOnline = string.Format("Url={0}; Username={1}; Password={2};authtype=Office365;", crmServerUrl, userName, password);

            CrmServiceClient conn = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connectionStringCrmOnline);

            IOrganizationService _service = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        ClientScriptManager csm            = Page.ClientScript;
        string display                     = "";
        string orderid                     = Request["orderid"];
        string connectionString            = GetServiceConfiguration();
        Dictionary <string, object> result = new Dictionary <string, object>();
        string json = "";

        if (connectionString != null && orderid != null)
        {
            CrmServiceClient conn = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connectionString);
            _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;

            DataSet    dataSet          = new DataSet("salesorder");
            DataTable  table            = new DataTable("salesorders");
            DataColumn col_order_id     = new DataColumn("processid");
            DataColumn col_order_number = new DataColumn("ordernumber");
            DataColumn col_order_status = new DataColumn("new_shippingstatus");
            table.Columns.Add(col_order_id);
            table.Columns.Add(col_order_number);
            table.Columns.Add(col_order_status);
            dataSet.Tables.Add(table);

            QueryExpression qe = new QueryExpression("salesorder");
            qe.ColumnSet = new ColumnSet("ordernumber", "new_shippingstatus", "name");
            qe.Criteria.AddCondition("name", ConditionOperator.Equal, orderid);
            EntityCollection results = _orgService.RetrieveMultiple(qe);
            if (results.Entities != null)
            {
                foreach (Entity order in results.Entities)
                {
                    DataRow newRow = table.NewRow();
                    newRow["processid"]          = order.Id.ToString();
                    newRow["ordernumber"]        = order["name"];
                    newRow["new_shippingstatus"] = order.FormattedValues["new_shippingstatus"].ToString();
                    table.Rows.Add(newRow);
                }
            }

            json = JsonConvert.SerializeObject(dataSet, Formatting.Indented);
            Response.ContentType = "application/json; charset=utf-8";
            Response.Write(json);
        }
        else
        {
            display = "Invalid prodid";
            csm.RegisterClientScriptBlock(this.GetType(), "Pop", "alert('" + display + "');", true);
        }
    }
Exemplo n.º 6
0
 public static IOrganizationService GetService()
 {
     try
     {
         var connString               = "Url=https://xxxxxx.crm.dynamics.com; [email protected]; Password=xxxxxx; authtype=Office365";
         CrmServiceClient     conn    = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connString);
         IOrganizationService service = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;
         var rtn = service.Execute(new WhoAmIRequest());
         return(service);
     }
     catch (Exception ex)
     {
         throw new Exception("Unable to connect to Dynamics");
     }
 }
Exemplo n.º 7
0
        private void ImportContacts()
        {
            CrmServiceClient conn = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(ConfigurationManager.ConnectionStrings["CRM Online"].ConnectionString);

            // Cast the proxy client to the IOrganizationService interface.
            IOrganizationService _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;

            foreach (var item in _contacts)
            {
                Entity contact = new Entity("contact");
                contact["firstname"]    = item.FirstName;
                contact["lastname"]     = item.LastName;
                contact["governmentid"] = item.IDNo;
            }
        }
Exemplo n.º 8
0
        public static List <PortalUser> RetreiveRecords()
        {
            CrmServiceClient conn = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connectionString);

            using (OrganizationService service = new OrganizationService("CRM"))
            {
                QueryExpression query = new QueryExpression
                {
                    EntityName = "portal_test",
                    ColumnSet  = new ColumnSet("kur_dev_portal_testid", "kur_dev_name", "kur_dev_login", "kur_dev_password")
                };
                List <PortalUser> info          = new List <PortalUser>();
                EntityCollection  accountRecord = service.RetrieveMultiple(query);
                if (accountRecord != null && accountRecord.Entities.Count > 0)
                {
                    PortalUser portalUserModel;
                    for (int i = 0; i < accountRecord.Entities.Count; i++)
                    {
                        portalUserModel = new PortalUser();

                        if (accountRecord[i].Contains("kur_dev_portal_testid") && accountRecord[i]["kur_dev_portal_testid"] != null)
                        {
                            portalUserModel.PortalUSerId = (Guid)accountRecord[i]["kur_dev_portal_testid"];
                        }

                        if (accountRecord[i].Contains("kur_dev_name") && accountRecord[i]["kur_dev_name"] != null)
                        {
                            portalUserModel.Name = accountRecord[i]["kur_dev_name"].ToString();
                        }

                        if (accountRecord[i].Contains("kur_dev_login") && accountRecord[i]["kur_dev_login"] != null)
                        {
                            portalUserModel.Login = accountRecord[i]["kur_dev_login"].ToString();
                        }

                        if (accountRecord[i].Contains("kur_dev_password") && accountRecord[i]["kur_dev_password"] != null)
                        {
                            portalUserModel.PassWord = accountRecord[i]["kur_dev_password"].ToString();
                        }

                        info.Add(portalUserModel);
                    }
                }
                return(info);
            }
        }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            Console.WriteLine("Conexion...");

            string connectionString = ConfigurationManager.ConnectionStrings["CRM"].ConnectionString;

            CrmServiceClient conn = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connectionString);


            if (conn.IsReady)
            {
                Console.WriteLine("Conectado");
                OrganizationServiceContext context    = new OrganizationServiceContext(conn);
                IOrganizationService       crmService = conn.OrganizationServiceProxy;
                QueryExpression            query      = new QueryExpression {
                    EntityName = "account", ColumnSet = new ColumnSet(new string[] { "name", "telephone1", "emailaddress1" })
                };

                EntityCollection account  = crmService.RetrieveMultiple(query);
                string           nombre   = "";
                string           email    = "";
                string           telefono = "";
                Console.WriteLine("Presione cualquier tecla para obtener los datos de la cuenta \n");
                Console.ReadKey();

                foreach (var count in account.Entities)
                {
                    nombre   = count.GetAttributeValue <string>("name");
                    telefono = !string.IsNullOrEmpty(count.GetAttributeValue <string>("telephone1")) ? count.GetAttributeValue <string>("telephone1") : "N/D";
                    email    = !string.IsNullOrEmpty(count.GetAttributeValue <string>("emailaddress1")) ? count.GetAttributeValue <string>("emailaddress1") : "N/D";
                    string resultado = string.Format("Nombre: {0} | Telefono: {1} | Email: {2}", nombre, telefono, email);
                    Console.WriteLine(resultado);
                }
                Console.WriteLine();
                Console.WriteLine("Total cuentas: " + account.Entities.Count);
                Console.WriteLine("Pulsa cualquier tecla para terminar");
                Console.ReadKey();
            }
            else
            {
                Console.WriteLine("Error de conexion");
            }
        }
Exemplo n.º 10
0
        // OrganizationServiceProxy _orgServiceProxy = null;

        public static IOrganizationService connect()
        {
            //Connecting to Dynamics 365 using Xrm.Sdk.Tooling.Connector
            CrmServiceClient connection;

            try
            {
                string connectionString = ConfigurationManager.ConnectionStrings["CRM"].ConnectionString;
                connection = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connectionString);

                connection.OrganizationServiceProxy.Timeout = new TimeSpan(0, 10, 0);

                // This statement is required to enable early-bound type support.
                connection.OrganizationServiceProxy.EnableProxyTypes();


                // Connect to the Organization service.
                IOrganizationService orgService = (IOrganizationService)connection.OrganizationWebProxyClient != null ? (IOrganizationService)connection.OrganizationWebProxyClient : (IOrganizationService)connection.OrganizationServiceProxy;

                //_orgServiceProxy = new OrganizationServiceProxy(connection);


                //OrganizationWebProxyClient Implements IOrganizationService and provides an authenticated connection to the Organization.svc/web endpoint. This /web endpoint is also used by web resources.
                //OrganizationServiceProxy  class implements the IOrganizationService and provides an authenticated WCF channel to the organization service

                if (!connection.IsReady)
                {
                    Console.WriteLine("Connection failed");

                    Console.WriteLine(connection.LastCrmError);
                    Console.WriteLine(connection.LastCrmException);
                }
                return(orgService);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Connection failed Error while create connection to crm ");

                Console.WriteLine(ex.Message);
                return(null);
            }
        }
        /// <summary>
        /// The Connect() method first connects to the organization service.
        /// </summary>
        /// <param name="connectionString">Provides service connection information.</param>
        /// <param name="promptforDelete">When True, the user will be prompted to delete all
        /// created entities.</param>
        public void Connect(String connectionString, bool promptforDelete)
        {
            try
            {
                // Establish a connection to the organization web service.
                Print("Connecting to the server ...");

                // Connect to the CRM web service using a connection string.
                CrmServiceClient conn = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connectionString);

                // Cast the proxy client to the IOrganizationService interface.
                _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;
                Print("connected");

                // Obtain information about the logged on user from the web service.
                Guid       userid     = ((WhoAmIResponse)_orgService.Execute(new WhoAmIRequest())).UserId;
                SystemUser systemUser = (SystemUser)_orgService.Retrieve("systemuser", userid,
                                                                         new ColumnSet(new string[] { "firstname", "lastname" }));
                Println("Logged on user is " + systemUser.FirstName + " " + systemUser.LastName + ".");

                // Retrieve the version of Microsoft Dynamics CRM.
                RetrieveVersionRequest  versionRequest  = new RetrieveVersionRequest();
                RetrieveVersionResponse versionResponse =
                    (RetrieveVersionResponse)_orgService.Execute(versionRequest);
                Println("Microsoft Dynamics CRM version " + versionResponse.Version + ".");

                //enable the action buttons when a connection is available
                this.btnCreate.IsEnabled   = true;
                this.btnRetrieve.IsEnabled = true;
                this.btnUpdate.IsEnabled   = true;
                this.btnDelete.IsEnabled   = true;
            }

            // Catch any service fault exceptions that Microsoft Dynamics CRM throws.
            catch (FaultException <OrganizationServiceFault> )
            {
                // You can handle an exception here or pass it back to the calling method.
                throw;
            }
        }
Exemplo n.º 12
0
        protected IOrganizationService GetOrgService()
        {
            var connection = ConfigurationManager.ConnectionStrings["fakexrmeasy-connection"];
            if (connection == null)
                throw new Exception("A connectionstring parameter with name 'fakexrmeasy-connection' must exist");

            if(string.IsNullOrWhiteSpace(connection.ConnectionString))
            {
                throw new Exception("The connectionString property must not be blank");
            }

            #if FAKE_XRM_EASY_2016

            // Connect to the CRM web service using a connection string.
            CrmServiceClient client = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connection.ConnectionString);
            return client;

            #else
            CrmConnection crmConnection = CrmConnection.Parse(connection.ConnectionString);
            OrganizationService service = new OrganizationService(crmConnection);
            return service;
            #endif
        }
Exemplo n.º 13
0
        protected IOrganizationService GetOrgService()
        {
            var connection = ConfigurationManager.ConnectionStrings[ConnectionStringName];

            if (connection == null)
            {
                throw new Exception(string.Format("A connectionstring parameter with name '{0}' must exist", ConnectionStringName));
            }

            if (string.IsNullOrWhiteSpace(connection.ConnectionString))
            {
                throw new Exception("The connectionString property must not be blank");
            }

#if FAKE_XRM_EASY_2016 || FAKE_XRM_EASY_365
            // Connect to the CRM web service using a connection string.
            CrmServiceClient client = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connection.ConnectionString);
            return(client);
#else
            CrmConnection       crmConnection = CrmConnection.Parse(connection.ConnectionString);
            OrganizationService service       = new OrganizationService(crmConnection);
            return(service);
#endif
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        ClientScriptManager csm            = Page.ClientScript;
        string display                     = "";
        string prodid                      = Request["prodid"];
        string connectionString            = GetServiceConfiguration();
        Dictionary <string, object> result = new Dictionary <string, object>();
        string json = "";

        if (connectionString != null && prodid != null)
        {
            display = "Invalid prodid";
            csm.RegisterClientScriptBlock(this.GetType(), "Pop", "alert('" + display + "');", true);

            CrmServiceClient conn = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connectionString);
            _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;

            DataSet    dataSet            = new DataSet("product");
            DataTable  table              = new DataTable("products");
            DataColumn col_product_id     = new DataColumn("productId");
            DataColumn col_product_name   = new DataColumn("productName");
            DataColumn col_product_number = new DataColumn("productNumber");
            //DataColumn col_product_parent = new DataColumn("productcategory");
            DataColumn col_amount_value = new DataColumn("productprice");
            //DataColumn col_product_description = new DataColumn("description");
            //DataColumn col_product_image = new DataColumn("image");
            DataColumn col_product_url = new DataColumn("url");
            table.Columns.Add(col_product_id);
            table.Columns.Add(col_product_name);
            //table.Columns.Add(col_product_parent);
            table.Columns.Add(col_product_number);
            table.Columns.Add(col_amount_value);
            //table.Columns.Add(col_product_description);
            //table.Columns.Add(col_product_image);
            table.Columns.Add(col_product_url);
            dataSet.Tables.Add(table);

            QueryExpression qe = new QueryExpression("product");
            qe.ColumnSet = new ColumnSet("name", "productnumber", "price", "parentproductid", "description", "adx_partialurl");
            qe.Criteria.AddCondition("productnumber", ConditionOperator.Equal, prodid);
            EntityCollection results = _orgService.RetrieveMultiple(qe);
            if (results.Entities != null)
            {
                foreach (Entity product in results.Entities)
                {
                    DataRow newRow = table.NewRow();
                    newRow["productId"]     = product.Id.ToString();
                    newRow["productName"]   = product["name"];
                    newRow["productNumber"] = product["productnumber"];
                    //newRow["productcategory"] = product.GetAttributeValue<EntityReference>("parentproductid").Name;
                    newRow["productprice"] = ((Money)(product["price"])).Value.ToString("0.00", CultureInfo.InvariantCulture);
                    //newRow["description"] = product["description"];
                    newRow["url"] = product["adx_partialurl"];

                    //EntityReference productRef = new EntityReference("product", new Guid(product.Id.ToString()));
                    //RelationshipQueryCollection relationshipQueryColl = new RelationshipQueryCollection();
                    //Relationship relationship = new Relationship();
                    //relationship.SchemaName = "productsalesliterature_association";
                    //QueryExpression qe2 = new QueryExpression("salesliterature");
                    //qe2.ColumnSet = new ColumnSet(true);
                    //relationshipQueryColl.Add(relationship, qe2);

                    //RetrieveRequest retrieveRequest = new RetrieveRequest();
                    //retrieveRequest.RelatedEntitiesQuery = relationshipQueryColl;
                    //retrieveRequest.Target = productRef;
                    //retrieveRequest.ColumnSet = new ColumnSet(true);
                    ////CrmConnection connection = new CrmConnection("CRM");
                    //string connectionString2 = GetServiceConfiguration();

                    ////using (var _serviceProxy = new OrganizationService(connection))
                    //if (connectionString2 != null)
                    //{
                    //    //OrganizationResponse response = _serviceProxy.Execute(retrieveRequest);
                    //    CrmServiceClient conn2 = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connectionString2);
                    //    _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;
                    //    OrganizationResponse response = _orgService.Execute(retrieveRequest);
                    //    Entity product2 = (Entity)response.Results["Entity"];
                    //    EntityCollection ecRelatedSalesLiterature = product2.RelatedEntities[relationship];

                    //    if (ecRelatedSalesLiterature.Entities != null)
                    //    {
                    //        QueryExpression qe3 = new QueryExpression("salesliteratureitem");
                    //        qe3.ColumnSet = new ColumnSet(true);
                    //        qe3.Criteria.AddCondition("salesliteratureid", ConditionOperator.Equal, ecRelatedSalesLiterature.Entities[0].Id);
                    //        EntityCollection results2 = _orgService.RetrieveMultiple(qe3);
                    //        if (results2.Entities != null)
                    //        {
                    //            newRow["image"] = results2.Entities[0]["documentbody"];
                    //        }
                    //    }
                    //    // do whatever you want
                    //}
                    table.Rows.Add(newRow);
                }
            }

            json = JsonConvert.SerializeObject(dataSet, Formatting.Indented);
            Response.ContentType = "application/json; charset=utf-8";
            Response.Write(json);
        }
        else
        {
            display = "Invalid prodid";
            csm.RegisterClientScriptBlock(this.GetType(), "Pop", "alert('" + display + "');", true);
        }
    }