locked
how to connect to crm2015 online through c# code in case of single sign on RRS feed

  • Question

  • Hi,

    I am looking for a code that will help me connect to CRM online site through my c# code without passing the password.

    My CRM Application supports single sign on. i.e after i enter into my client network (through VPN) with the specified credentials and open the CRM site , it only requires the username as username@domain.com and no password and it is redirected to crm site.

    Now i have some portal applications that connect to CRM and perfrom CRUD operations.

    So i have a doubt in this scenario - 

    Once i am in the network and run the portal exe do i need to use only the basic code to connect to CRM and it will help me connect as given below - 

     OrganizationService _orgService;
                CrmConnection connection = new CrmConnection("Crm");

                try
                {
                    _orgService = new OrganizationService(connection);
                }
                catch (Exception ex)
                {
                    throw (ex.InnerException);
                }

                return _orgService;

    Or do i need to use the below code - 

     OrganizationServiceProxy serviceProxy = null;

                String url = "https://xxxxx.api.crm4.dynamics.com/XRMServices/2011/Organization.svc";


                Uri organizationUri = new Uri(url);

                IServiceManagement<IOrganizationService> orgServiceManagement =
                      ServiceConfigurationFactory.CreateManagement<IOrganizationService>(
                       organizationUri);

                AuthenticationProviderType endpointType = orgServiceManagement.AuthenticationType;

               

                if (endpointType == AuthenticationProviderType.OnlineFederation)
                {
                   
                    AuthenticationCredentials authCredentials = new AuthenticationCredentials();
                    authCredentials.UserPrincipalName = "username@domain.com";

                    AuthenticationCredentials tokenCredentials = orgServiceManagement.Authenticate(authCredentials);

                    SecurityTokenResponse responseToken = tokenCredentials.SecurityTokenResponse;

                    using (serviceProxy = new OrganizationServiceProxy(orgServiceManagement, responseToken))
                    {
                        serviceProxy.EnableProxyTypes();
                    }

                }

                return serviceProxy;

    Or is there someother way out.Please help.



    Sunday, October 18, 2015 2:57 PM

All replies

  • try to use the simplified connection and don't put username and password, just the url, and check if you can connect

    My blog: www.crmanswers.net - CRM Theme Generator

    Monday, October 19, 2015 4:40 AM
  • Add connection string to config file. Just specify the URL.

    <connectionStrings>
      <add name="Crm" connectionString="Url=http://crm.test.com/xrmContoso;"/>
    </connectionStrings>

    var connection = new CrmConnection("Crm");
    var service = new OrganizationService(connection);

    hope this helps.

    Tuesday, October 20, 2015 12:49 PM