It’s always a good idea to connect to your OnPremise MS CRM 2011 app through a Console Application, during your process of plugin development etc.
By doing majority of the features in the console app, you can save time during testing and debugging. Once all is done, porting your code into the plugin framework works well.
This post would enable you to build a console application which would connect to your OnPremise MS CRM 2011 app.
1. Create a New Console Application in your Visual Studio.
2. Add the following references from sdk/bin folder.
- AntiXSSLibrary.dll
- Microsoft.Crm.Sdk.Proxy.dll
- Microsoft.Xrm.Client.dll
- Microsoft.Xrm.Portal.dll
- Microsoft.Xrm.Portal.Files.dll
- Microsoft.Xrm.Sdk.dll
3. Add the following references in .Net
- Microsoft.IdentityModel.dll
- Microsoft.ServiceBus.dll
- System.Data.Services.dll
- System.Data.Services.Client.dll
- System.Runtime.Serialization.dll
In order to have the Microsoft.IdentityModel.dll file , please install Windows Identity Foundation.
4. Check the properties of the project. Make sure the console project is specifying “.NET Framework 4” as the target framework and not “.NET Framework 4 Client Profile.”
5. In the Program.cs file, have the basic using statements added.
using Microsoft.Xrm.Sdk;
using System.ServiceModel.Description;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Query;
6. Write a try catch block in the Main Function to test the connection.
public static void Main(string[] args) { try { ClientCredentials creds = new ClientCredentials(); creds.UserName.UserName = "username"; creds.UserName.Password = "password"; IOrganizationService service = new OrganizationServiceProxy(new Uri("http://servername/org/XRMServices/2011/Organization.svc"), null, creds, null); Console.WriteLine(" Connect Success"); Console.Read(); } catch (Exception ex) { Console.WriteLine("failed to connect" + ex.Message); Console.Read(); } }
Hope this serves as a starting point for some one in need ! 😉
Happy coding !