Integration to Microsoft Dynamic CRM 2011

本文关键字:CRM 2011 Dynamic Microsoft to Integration | 更新日期: 2023-09-27 17:59:14

如何使用CRM 2011 SDK和C#将您的应用程序集成到Microsoft CRM 2011?

编辑:我将问题移至答案,以遵循问答格式。根据Guido Preite的说法。

Integration to Microsoft Dynamic CRM 2011

因为我现在习惯于分享我每天学到的新东西,我只想在这里展示我是如何使用CRM 2011 SDK和C#连接到Microsoft CRM 2011的。这将帮助你不要像我刚才那样把头撞在墙上。

首先,将对项目的引用添加到Microsoft.Xrm.Sdk.dll。您可以从CRM 2011 Sdk中获得该引用(在此处下载:http://www.microsoft.com/en-us/download/details.aspx?id=24004)。

这是关于如何连接到CRM服务的代码:

    using Microsoft.Xrm.Sdk.Client;
    using Microsoft.Xrm.Sdk.Query;
    using Microsoft.Xrm.Sdk;
    //This is your Organization Service which you can find from the actual CRM UI. go to Settings>Customizations>Developer Resources.
    Uri organizationUri = new Uri("http://crmservername/organizationname/XRMServices/2011/Organization.svc"); 
    Uri homeRealmUri = null;
    ClientCredentials credentials = new ClientCredentials();
    //Instantiate your network credential that will access the CRM Server
    credentials.Windows.ClientCredential = new System.Net.NetworkCredential("username", "password", "domain");
    OrganizationServiceProxy orgProxy = new OrganizationServiceProxy(organizationUri, homeRealmUri, credentials, null);
    //Instantiate IOrganizationService so you can call the CRM service methods.
     IOrganizationService _service = (IOrganizationService)orgProxy
//from this you can now perform CRUD to your CRM. 
//I'm just going to provide some example on how to query your entities in CRM like so:
    QueryExpression query = new QueryExpression() { };
    query.EntityName = "country";
    query.ColumnSet = new ColumnSet("name", "2digitiso", "3digitiso");
    EntityCollection retrieved = _service.RetrieveMultiple(query);
    foreach (var item in retrieved.Entities)
    {
         MessageBox.Show(item["name"].ToString() + " " + item["2digitiso"].ToString() + " " + item["3digitiso"].ToString());
    }

参考:http://nishantrana.wordpress.com/2010/11/03/sample-code-for-using-iorganizationservice-in-crm-2011/
http://msdn.microsoft.com/en-us/library/gg334708.aspx
http://msdn.microsoft.com/en-us/library/gg328149.aspx
http://www.codeproject.com/Articles/559599/Integrating-your-applications-with-MS-CRM-Online

此外,如果你碰巧遇到这样的异常:

CRM Service Exception: Could not load file or assembly 'Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies

安装:Windows Identity Foundation(http://www.microsoft.com/en-us/download/details.aspx?id=17331)

我希望我在你的项目中帮助了你们中的一些人。