SBX - Search With Button

SBX - Forum Post Title

Unable to connect SDK metadata code to the ms crm online

Microsoft Dynamics CRM Forum

Amrutha B K asked a question on 24 May 2019 3:29 AM

Question Status

Suggested Answer

I tried by passing all the related url for example:trasfer.crm8.dynamics.com:443 and 444 ,8085 in console application, i am getting the error metadata contains a reference that cannot be resolved and not able to connect to the online ms crm, please any body suggest me.

Reply
Guido Preite responded on 24 May 2019 3:39 AM
My Badges

share your code

Reply
Dynamics365 Rocker responded on 24 May 2019 4:54 AM
My Badges
Suggested Answer

Check below post. It may help you:

community.dynamics.com/.../219620

Reply
Amrutha B K responded on 25 May 2019 12:49 AM

Its working for the onpremise ms crm ,but not for ms crm online version.

Reply
Pravin Pawar responded on 25 May 2019 1:28 AM
My Badges
Suggested Answer

Hi Amrutha,

Please refer below code its working for me on both type of instance:

public static IOrganizationService service;

   //DLL reference

   //using Microsoft.Xrm.Sdk.Client;

   //using System.ServiceModel.Description;

   //using System.Net;

   //using Microsoft.Xrm.Sdk.Query;

   //using Microsoft.Xrm.Sdk.Messages;

   //using Microsoft.Crm.Sdk.Messages;

   //using Microsoft.Xrm.Client.Services;

   //using Microsoft.Xrm.Client;

   public void MethodName()

   {

       ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

       Microsoft.Xrm.Client.CrmConnection connection = CrmConnection.Parse(GetServiceConfiguration());

       service = new OrganizationService(connection);

       {

           //Your code here

       }

   }

   public static String GetServiceConfiguration()

   {

       int count = ConfigurationManager.ConnectionStrings.Count;

       List<KeyValuePair<String, String>> filteredConnectionStrings =

           new List<KeyValuePair<String, String>>();

       for (int a = 0; a < count; a++)

       {

           if (isValidConnectionString(ConfigurationManager.ConnectionStrings[a].ConnectionString))

               filteredConnectionStrings.Add

                   (new KeyValuePair<string, string>

                       (ConfigurationManager.ConnectionStrings[a].Name,

                       ConfigurationManager.ConnectionStrings[a].ConnectionString));

       }

       if (filteredConnectionStrings.Count == 0)

       {

           Console.WriteLine("An app.config file containing at least one valid Microsoft Dynamics CRM " +

               "connection string configuration must exist in the run-time folder.");

           Console.WriteLine("\nThere are several commented out example connection strings in " +

               "the provided app.config file. Uncomment one of them and modify the string according " +

               "to your Microsoft Dynamics CRM installation. Then re-run the sample.");

           return null;

       }

       if (filteredConnectionStrings.Count == 1)

       {

           return filteredConnectionStrings[0].Value;

       }

       return null;

   }

   private static Boolean isValidConnectionString(String connectionString)

   {

       if (connectionString.Contains("Url=") || connectionString.Contains("Server=") || connectionString.Contains("ServiceUri="))

           return true;

       return false;

   }

   //<configuration>

   // <connectionStrings>

   // <add name= "Xrm" connectionString = "Url=crmdomainname.crm11.dynamics.com; Username=yourusername; Password=Userpassword; authtype=Office365" />

   //</connectionStrings>

   //</configuration>

Reply
Pravin Pawar responded on 25 May 2019 1:28 AM
My Badges
Suggested Answer

Hi Amrutha,

Please refer below code its working for me on both type of instance:

   public static String GetServiceConfiguration()

   {

       int count = ConfigurationManager.ConnectionStrings.Count;

       List<KeyValuePair<String, String>> filteredConnectionStrings =

           new List<KeyValuePair<String, String>>();

       for (int a = 0; a < count; a++)

       {

           if (isValidConnectionString(ConfigurationManager.ConnectionStrings[a].ConnectionString))

               filteredConnectionStrings.Add

                   (new KeyValuePair<string, string>

                       (ConfigurationManager.ConnectionStrings[a].Name,

                       ConfigurationManager.ConnectionStrings[a].ConnectionString));

       }

       if (filteredConnectionStrings.Count == 0)

       {

           Console.WriteLine("An app.config file containing at least one valid Microsoft Dynamics CRM " +

               "connection string configuration must exist in the run-time folder.");

           Console.WriteLine("\nThere are several commented out example connection strings in " +

               "the provided app.config file. Uncomment one of them and modify the string according " +

               "to your Microsoft Dynamics CRM installation. Then re-run the sample.");

           return null;

       }

       if (filteredConnectionStrings.Count == 1)

       {

           return filteredConnectionStrings[0].Value;

       }

       return null;

   }

   private static Boolean isValidConnectionString(String connectionString)

   {

       if (connectionString.Contains("Url=") || connectionString.Contains("Server=") || connectionString.Contains("ServiceUri="))

           return true;

       return false;

   }

Reply
Amrutha B K responded on 27 May 2019 6:43 AM

Actually, i tried by connecting to online ms crm it is connecting by using a console application in one system but not in another system,please any body suggest me.

Reply
Suggested Answer

Hi

You could download my sample application from my following github page and test and see if this works for you.

This sample project has all the libraries referenced

github.com/.../CRMServiceClientQuickStart

Reply
Dynamics365 Rocker responded on 24 May 2019 4:54 AM
My Badges
Suggested Answer

Check below post. It may help you:

community.dynamics.com/.../219620

Reply
Pravin Pawar responded on 25 May 2019 1:28 AM
My Badges
Suggested Answer

Hi Amrutha,

Please refer below code its working for me on both type of instance:

public static IOrganizationService service;

   //DLL reference

   //using Microsoft.Xrm.Sdk.Client;

   //using System.ServiceModel.Description;

   //using System.Net;

   //using Microsoft.Xrm.Sdk.Query;

   //using Microsoft.Xrm.Sdk.Messages;

   //using Microsoft.Crm.Sdk.Messages;

   //using Microsoft.Xrm.Client.Services;

   //using Microsoft.Xrm.Client;

   public void MethodName()

   {

       ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

       Microsoft.Xrm.Client.CrmConnection connection = CrmConnection.Parse(GetServiceConfiguration());

       service = new OrganizationService(connection);

       {

           //Your code here

       }

   }

   public static String GetServiceConfiguration()

   {

       int count = ConfigurationManager.ConnectionStrings.Count;

       List<KeyValuePair<String, String>> filteredConnectionStrings =

           new List<KeyValuePair<String, String>>();

       for (int a = 0; a < count; a++)

       {

           if (isValidConnectionString(ConfigurationManager.ConnectionStrings[a].ConnectionString))

               filteredConnectionStrings.Add

                   (new KeyValuePair<string, string>

                       (ConfigurationManager.ConnectionStrings[a].Name,

                       ConfigurationManager.ConnectionStrings[a].ConnectionString));

       }

       if (filteredConnectionStrings.Count == 0)

       {

           Console.WriteLine("An app.config file containing at least one valid Microsoft Dynamics CRM " +

               "connection string configuration must exist in the run-time folder.");

           Console.WriteLine("\nThere are several commented out example connection strings in " +

               "the provided app.config file. Uncomment one of them and modify the string according " +

               "to your Microsoft Dynamics CRM installation. Then re-run the sample.");

           return null;

       }

       if (filteredConnectionStrings.Count == 1)

       {

           return filteredConnectionStrings[0].Value;

       }

       return null;

   }

   private static Boolean isValidConnectionString(String connectionString)

   {

       if (connectionString.Contains("Url=") || connectionString.Contains("Server=") || connectionString.Contains("ServiceUri="))

           return true;

       return false;

   }

   //<configuration>

   // <connectionStrings>

   // <add name= "Xrm" connectionString = "Url=crmdomainname.crm11.dynamics.com; Username=yourusername; Password=Userpassword; authtype=Office365" />

   //</connectionStrings>

   //</configuration>

Reply
Pravin Pawar responded on 25 May 2019 1:28 AM
My Badges
Suggested Answer

Hi Amrutha,

Please refer below code its working for me on both type of instance:

   public static String GetServiceConfiguration()

   {

       int count = ConfigurationManager.ConnectionStrings.Count;

       List<KeyValuePair<String, String>> filteredConnectionStrings =

           new List<KeyValuePair<String, String>>();

       for (int a = 0; a < count; a++)

       {

           if (isValidConnectionString(ConfigurationManager.ConnectionStrings[a].ConnectionString))

               filteredConnectionStrings.Add

                   (new KeyValuePair<string, string>

                       (ConfigurationManager.ConnectionStrings[a].Name,

                       ConfigurationManager.ConnectionStrings[a].ConnectionString));

       }

       if (filteredConnectionStrings.Count == 0)

       {

           Console.WriteLine("An app.config file containing at least one valid Microsoft Dynamics CRM " +

               "connection string configuration must exist in the run-time folder.");

           Console.WriteLine("\nThere are several commented out example connection strings in " +

               "the provided app.config file. Uncomment one of them and modify the string according " +

               "to your Microsoft Dynamics CRM installation. Then re-run the sample.");

           return null;

       }

       if (filteredConnectionStrings.Count == 1)

       {

           return filteredConnectionStrings[0].Value;

       }

       return null;

   }

   private static Boolean isValidConnectionString(String connectionString)

   {

       if (connectionString.Contains("Url=") || connectionString.Contains("Server=") || connectionString.Contains("ServiceUri="))

           return true;

       return false;

   }

Reply
Suggested Answer

Hi

You could download my sample application from my following github page and test and see if this works for you.

This sample project has all the libraries referenced

github.com/.../CRMServiceClientQuickStart

Reply

SBX - Two Col Forum

SBX - Migrated JS