为Microsoft Dynamics CRM编写Web门户的编程

Dav*_*key 3 vb.net asp.net dynamics-crm-2011

我正在为将连接到Microsoft Dynamics的客户开发Web门户.我不想让Dynamics CRM直接面向面向Internet的部署(IFD),因此我想使用Web界面与之交互的单独数据库,然后使用Web服务在Web门户数据库和Dynamics之间移动数据CRM.我只是想知道这是否是最好的方法,以及是否有任何好的代码示例等我可以考虑实现这个?我看到微软有一个客户门户网站,但看起来它需要(粗略地看一眼)IFD部署 - 这是我不想要的.

Anw*_*war 6

首先,在创建ASP.NET项目(WebForms或MVC 3)之后,添加以下引用:

  1. Microsoft.crm.sdk.proxy.
  2. Microsoft.xrm.sdk.
  3. System.Runtime.序列化.
  4. System.ServiceModel.

在您的代码隐藏中创建一个类,然后添加以下代码:

private IOrganizationService GetCrmService(string userName, string password, string domain, Uri serviceUri)
{
    OrganizationServiceProxy _serviceProxy;

    ClientCredentials credentials = new ClientCredentials();
    credentials.Windows.ClientCredential = new System.Net.NetworkCredential(userName, password, domain);
    //credentials.UserName.UserName = userName;  // uncomment in case you want to impersonate
    //credentials.UserName.Password = password;
    ClientCredentials deviceCredentials = new ClientCredentials();

    using (_serviceProxy = new OrganizationServiceProxy(serviceUri,
                                                        null,
                                                        credentials,
                                                        deviceCredentials))
    {
        _serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
        return (IOrganizationService)_serviceProxy;
    }
}
Run Code Online (Sandbox Code Playgroud)

如果要检索多个记录:

string fetch = @"My Fetch goes here";
EntityCollection records = getCrmService().RetrieveMultiple(new FetchExpression(fetch));
Run Code Online (Sandbox Code Playgroud)

我强烈建议您下载SDK或检查一下 您将找到许多示例和演练,这些将帮助您构建良好的门户.