none
CRM 2011 Online Authentication for Custom Web application RRS feed

  • Pregunta

  • Estoy usando el siguiente código del foro http://kellyhoang.blogspot.mx/2012/06/crm-2011-online-authentication-for.html?showComment=1360798697246#c28470344161919824, pero no me funciona me marca en rojo lo que esta subrayado, y no s epor que si ya importe las referencias y los elementos, alguien sabe otra forma de conectarse a crm online y que si funcione?

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    using System.ServiceModel.Description;
    using Microsoft.Xrm.Sdk.Client;
    using Microsoft.Crm;
    using Microsoft.Crm.Tools;
    using System.Net;
    using Microsoft.Xrm.Sdk;
    using Microsoft.Crm.Services.Utility;

    public partial class _Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
            }

            private static ClientCredentials GetDeviceCredentials()
            {
                return Microsoft.Crm.Services.Utility.DeviceIdManager.LoadOrRegisterDevice();
            }

            protected void Button1_Click(object sender, EventArgs e)
            {
                //Authenticate using credentials of the logged in user;
                string UserName = "";   //your Windows Live ID
                string Password = "";    // your password
                ClientCredentials Credentials = new ClientCredentials();
                Credentials.UserName.UserName = UserName;
                Credentials.UserName.Password = Password;

                Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
                //This URL needs to be updated to match the servername and Organization for the environment.
                Uri OrganizationUri = new Uri("");           //this URL could copy from Setting --> Developer Source 

                Uri HomeRealmUri = null;
                //OrganizationServiceProxy serviceProxy;   
                using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, GetDeviceCredentials()))
                {
                    IOrganizationService service = (IOrganizationService)serviceProxy;

                    //Instantiate the contact object and populate the attributes.                      
                    Contact contact = new Contact();
                    contact.FirstName = txtFirstName.Text.ToString();
                    contact.LastName = txtLastName.Text.ToString();
                    contact.EMailAddress1 = txtEmailAddress.Text.ToString();
                    Guid newContactId = service.Create(contact);

                    //This code will clear the textboxes after the contact is created.
                    txtFirstName.Text = "";
                    txtLastName.Text = "";
                    txtEmailAddress.Text = "";
                    txtPhoneNumber.Text = "";

                }
            }

        }


    • Editado Mlp24 viernes, 15 de febrero de 2013 21:46
    viernes, 15 de febrero de 2013 16:21

Todas las respuestas

  • Hola Revisa la version de Framework (debería ser 4.0 creo).

    prueba y nos dices. De todos modos te recomiendo utilizar entidades dinámica (clase "Entity") en lugar de las tipadas (como en este caso "Contact").

    para diferencias entre Late bound y Early bound mira: http://www.magnetismsolutions.com/blog/roshanmehta/2012/05/04/dynamics_crm_2011_early_vs._late_binding_overview

    un saludo,


    Demian Adolfo Raschkovan Blog: http://crmtoall.blogspot.com If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    viernes, 15 de febrero de 2013 16:37
    Moderador
  • Efectivamente mi Framework es el 4 y aun asi marca errores
    viernes, 15 de febrero de 2013 16:52
  • Ya realice lo de modificar a la clase entidad por lo que ya no me amrca errores lo de Contact, pero lo de services me sigue generando problemas, y si tengo el Framewoek 4

    Using System;

    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    using System.ServiceModel.Description;
    using Microsoft.Xrm.Sdk.Client;
    using Microsoft.Crm;
    using Microsoft.Crm.Tools;
    using System.Net;
    using Microsoft.Xrm.Sdk;
    using Microsoft.Crm.Services.Utility;

    public partial class _Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
            }

            private static ClientCredentials GetDeviceCredentials()
            {
                return Microsoft.Crm.Services.Utility.DeviceIdManager.LoadOrRegisterDevice();
            }

            protected void Button1_Click(object sender, EventArgs e)
            {
                //Authenticate using credentials of the logged in user;
                string UserName = "";   //your Windows Live ID
                string Password = "";    // your password
                ClientCredentials Credentials = new ClientCredentials();
                Credentials.UserName.UserName = UserName;
                Credentials.UserName.Password = Password;

                Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
                //This URL needs to be updated to match the servername and Organization for the environment.
                Uri OrganizationUri = new Uri("");           //this URL could copy from Setting --> Developer Source 

                Uri HomeRealmUri = null;
                //OrganizationServiceProxy serviceProxy;   
                using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, GetDeviceCredentials()))
                {
                    IOrganizationService service = (IOrganizationService)serviceProxy;

                    //Instantiate the contact object and populate the attributes.                      
                    Entity contact = new Entity("contact");
                    contact["FirstName"] = txtFirstName.Text.ToString();
                    contact["LastName"] = txtLastName.Text.ToString();
                    contact["EMailAddress1"] = txtEmailAddress.Text.ToString();
                    Guid newContactId = service.Create(contact);

                    //This code will clear the textboxes after the contact is created.
                    txtFirstName.Text = "";
                    txtLastName.Text = "";
                    txtEmailAddress.Text = "";
                    txtPhoneNumber.Text = "";

                }
            }

        }


    • Editado Mlp24 viernes, 15 de febrero de 2013 21:46
    viernes, 15 de febrero de 2013 17:09
  • Hola Maria

    Como norma general, te recomiendo borrar todos los datos sensibles, tales como Usuario, password y la Url de tu CRM


    Salu2 Atilin | http://www.dexrm.com

    viernes, 15 de febrero de 2013 21:43
  • Gracias, no lo note como anda una un poco presionada, pero gracias

    viernes, 15 de febrero de 2013 21:47