locked
Urgent : How to authenticate and retrieve data from Microsoft Dynamics CRM 2011 (Web) RRS feed

  • Question

  • Hello All,

    I am new to Microsoft Dynamics CRM. I added SOAP service reference in my project like "https://SERVERNAME/XRMServices/2011/Organization.svc" named "MicrosoftDynamicsCRMSoapService" and I am able to create client object as :

    MicrosoftDynamicsCRMSoapService.OrganizationServiceClient organizationServiceClient =

    new MicrosoftDynamicsCRMSoapService.OrganizationServiceClient();

    Now can you please tell me that how to authenticate and access data (like account, contact etc) using this client object ?


    • Edited by JaiHariHar Friday, August 23, 2013 9:09 AM
    Friday, August 23, 2013 7:53 AM

Answers

  • Hi,

    credentials.UserName.UserName = ConfigurationManager.AppSettings["username"];

                credentials
    .UserName.Password = ConfigurationManager.AppSettings["userPassword"];

                device
    Credentials.UserName.UserName = ConfigurationManager.AppSettings["dusername"];
                device
    Credentials.UserName.Password = ConfigurationManager.AppSettings["duserid"]; organizationUri = new Uri(ConfigurationManager.AppSettings["orgurl"]);

                home
    RealmUri = null;
               
    using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(organizationUri, homeRealmUri, credentials, deviceCredentials))
               
    {
                   
    IOrganizationService service = (IOrganizationService)serviceProxy;

    // your Code ....

                 }

    Refer the below links it will helps you,

    http://kellyhoang.blogspot.in/2012/06/crm-2011-online-authentication-for.html

    http://www.c-sharpcorner.com/UploadFile/aravindbenator/crm-2011-online/

    http://msdn.microsoft.com/en-us/library/gg509027.aspx

    http://msdn.microsoft.com/en-us/library/gg695790.aspx

    http://blogs.msdn.com/b/devkeydet/archive/2013/02/19/calling-crm-from-asp-net-using-impersonation-to-actonbehalfof-the-logged-in-user.aspx

     

    • Marked as answer by JaiHariHar Friday, August 23, 2013 2:28 PM
    Friday, August 23, 2013 9:15 AM
  • To authenticate and Retrieve data (e.g. opportunity, contact, account), I am now using following type of code :

    #region Authenticate and Retrieve Details from the CRM #region Authentication and Proxy Creation string UserName = "username"; //your Windows Live ID or Microsoft Dynamics CRM ID string Password = "password"; // your password Uri OrganizationUri = new Uri("https://SERVERNAME/XRMServices/2011/Organization.svc"); ClientCredentials Credentials = new ClientCredentials(); Credentials.UserName.UserName = UserName; Credentials.UserName.Password = Password; //OrganizationServiceProxy serviceProxy; using (OrganizationServiceProxy serviceProxy =

    new OrganizationServiceProxy(OrganizationUri, null, Credentials, GetDeviceCredentials())) { IOrganizationService service = (IOrganizationService)serviceProxy; #endregion Authentication and Proxy Creation #region Query expression //opportunityQuery QueryExpression opportunityQuery = new QueryExpression { EntityName = "opportunity", ColumnSet = new ColumnSet("name") }; //accountQuery QueryExpression accountQuery = new QueryExpression { EntityName = "account", ColumnSet = new ColumnSet("name") }; //contactQuery QueryExpression contactQuery = new QueryExpression { EntityName = "contact", ColumnSet = new ColumnSet("fullname") }; #endregion Query expression #region Retrieving Records var opportunities = service.RetrieveMultiple(opportunityQuery); var accounts = service.RetrieveMultiple(accountQuery); var contacts = service.RetrieveMultiple(contactQuery);

                             #endregion Retrieving Records

    #endregion Authenticate and Retrieve Details from the CRM





    • Marked as answer by JaiHariHar Friday, August 23, 2013 2:38 PM
    • Edited by JaiHariHar Friday, August 23, 2013 2:41 PM
    Friday, August 23, 2013 2:36 PM

All replies

  • Hi,

    credentials.UserName.UserName = ConfigurationManager.AppSettings["username"];

                credentials
    .UserName.Password = ConfigurationManager.AppSettings["userPassword"];

                device
    Credentials.UserName.UserName = ConfigurationManager.AppSettings["dusername"];
                device
    Credentials.UserName.Password = ConfigurationManager.AppSettings["duserid"]; organizationUri = new Uri(ConfigurationManager.AppSettings["orgurl"]);

                home
    RealmUri = null;
               
    using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(organizationUri, homeRealmUri, credentials, deviceCredentials))
               
    {
                   
    IOrganizationService service = (IOrganizationService)serviceProxy;

    // your Code ....

                 }

    Refer the below links it will helps you,

    http://kellyhoang.blogspot.in/2012/06/crm-2011-online-authentication-for.html

    http://www.c-sharpcorner.com/UploadFile/aravindbenator/crm-2011-online/

    http://msdn.microsoft.com/en-us/library/gg509027.aspx

    http://msdn.microsoft.com/en-us/library/gg695790.aspx

    http://blogs.msdn.com/b/devkeydet/archive/2013/02/19/calling-crm-from-asp-net-using-impersonation-to-actonbehalfof-the-logged-in-user.aspx

     

    • Marked as answer by JaiHariHar Friday, August 23, 2013 2:28 PM
    Friday, August 23, 2013 9:15 AM
  • Thanks a lot B sreenivasulu, the links were very helpful for me.
    • Edited by JaiHariHar Friday, August 23, 2013 2:32 PM
    Friday, August 23, 2013 2:31 PM
  • To authenticate and Retrieve data (e.g. opportunity, contact, account), I am now using following type of code :

    #region Authenticate and Retrieve Details from the CRM #region Authentication and Proxy Creation string UserName = "username"; //your Windows Live ID or Microsoft Dynamics CRM ID string Password = "password"; // your password Uri OrganizationUri = new Uri("https://SERVERNAME/XRMServices/2011/Organization.svc"); ClientCredentials Credentials = new ClientCredentials(); Credentials.UserName.UserName = UserName; Credentials.UserName.Password = Password; //OrganizationServiceProxy serviceProxy; using (OrganizationServiceProxy serviceProxy =

    new OrganizationServiceProxy(OrganizationUri, null, Credentials, GetDeviceCredentials())) { IOrganizationService service = (IOrganizationService)serviceProxy; #endregion Authentication and Proxy Creation #region Query expression //opportunityQuery QueryExpression opportunityQuery = new QueryExpression { EntityName = "opportunity", ColumnSet = new ColumnSet("name") }; //accountQuery QueryExpression accountQuery = new QueryExpression { EntityName = "account", ColumnSet = new ColumnSet("name") }; //contactQuery QueryExpression contactQuery = new QueryExpression { EntityName = "contact", ColumnSet = new ColumnSet("fullname") }; #endregion Query expression #region Retrieving Records var opportunities = service.RetrieveMultiple(opportunityQuery); var accounts = service.RetrieveMultiple(accountQuery); var contacts = service.RetrieveMultiple(contactQuery);

                             #endregion Retrieving Records

    #endregion Authenticate and Retrieve Details from the CRM





    • Marked as answer by JaiHariHar Friday, August 23, 2013 2:38 PM
    • Edited by JaiHariHar Friday, August 23, 2013 2:41 PM
    Friday, August 23, 2013 2:36 PM