locked
unable to connect to online crm using API RRS feed

  • Question

  • hey guyz, im trying to access online crm using the crm API.

    locally im able to connect to CRM using the API and do lot of activities, but when im trying the same thing for the online crm provided by microsoft, it says "The user authentication failed!" when retrieving a entity collection using  organization service. 

    im using the following method to create the organization service,

    public static IOrganizationService GetOrganizationService(string serverName, string username, string password, string domain)
            {
                string serverUri = serverName + "/XRMServices/2011/Organization.svc";
                Uri organizationUri = new Uri(serverUri);
                ClientCredentials cred = new ClientCredentials();
                // set default credentials for OrganizationService
                cred.Windows.ClientCredential = new NetworkCredential(username, password, domain);
                OrganizationServiceProxy _serviceproxy = new OrganizationServiceProxy(organizationUri, null, cred, null);
                _serviceproxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
                IOrganizationService _service = (IOrganizationService)_serviceproxy;
                return _service;
            }

    please help me guyz, what do i need to do here???... my crm online user id is 


    so i tried the credentials as

    new NetworkCredential(username, password);

    when i passed the user name as haroon@haroon5048.onmicrosoft.com

    and when i supplied username and domain differently i used

    new NetworkCredential(username, password, domain);


    can any one please help me..

    Wednesday, September 19, 2012 12:13 PM

Answers

  • yeah i got it solved, actually i was missing the below line.

    IServiceConfiguration<IOrganizationService> 

    and this is how my working code looks like

     string serverUri = serverName + "/XRMServices/2011/Organization.svc";
                Uri organizationUri = new Uri(serverUri);
                ClientCredentials cred = new ClientCredentials();
                // set default credentials for OrganizationService
                cred.UserName.UserName = username;
                cred.UserName.Password = password;
                IServiceConfiguration<IOrganizationService> config = ServiceConfigurationFactory.CreateConfiguration<IOrganizationService>(organizationUri);
                OrganizationServiceProxy _serviceproxy = new OrganizationServiceProxy(config,cred);
                _serviceproxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
                IOrganizationService _service = (IOrganizationService)_serviceproxy;
                return _service;

     

    Hope this helps others.

    • Marked as answer by SyedHaroon Wednesday, September 19, 2012 3:31 PM
    Wednesday, September 19, 2012 3:30 PM

All replies

  • Hello,

    You should download latest SDK. I believe it would solve your issue.


    Freelance Developer for Dynamics CRM 4.0/2011

    Wednesday, September 19, 2012 12:21 PM
    Moderator
  • yeah i got it solved, actually i was missing the below line.

    IServiceConfiguration<IOrganizationService> 

    and this is how my working code looks like

     string serverUri = serverName + "/XRMServices/2011/Organization.svc";
                Uri organizationUri = new Uri(serverUri);
                ClientCredentials cred = new ClientCredentials();
                // set default credentials for OrganizationService
                cred.UserName.UserName = username;
                cred.UserName.Password = password;
                IServiceConfiguration<IOrganizationService> config = ServiceConfigurationFactory.CreateConfiguration<IOrganizationService>(organizationUri);
                OrganizationServiceProxy _serviceproxy = new OrganizationServiceProxy(config,cred);
                _serviceproxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
                IOrganizationService _service = (IOrganizationService)_serviceproxy;
                return _service;

     

    Hope this helps others.

    • Marked as answer by SyedHaroon Wednesday, September 19, 2012 3:31 PM
    Wednesday, September 19, 2012 3:30 PM