2011-04-14 83 views
2

我正在編寫使用XRM 2011使用Early Bound的MVC 3 WebApp。這是一個面向互聯網的應用程序,託管在不同於Dynamics IIS的計算機上。XRM/Dynamics CRM 2011中OrganizationServiceProxy的連接/對象池

這當然會使OrganizationServiceProxy調用非常頻繁,響應在每次第一次碰撞時都會變得緩慢。

建議重用OrganizationServiceProxy連接而不是每次創建新實例?

如果是的話,

  1. 有什麼來管理連接,如
    • 連接池的應用程序 - MS或第三方/開源
    • 或類似WCF的一些框架(沒用過WCF,還有)
  2. 如果我必須編寫自己的代碼來管理連接,那麼推薦使用哪種設計模式?

對不起,來自MS網站的重複帖子。希望這個論壇更加活躍。

回答

2

幾個週期後,我發現,使用CrmConection是最快的方法。與上述緩存實現相比,CrmConnection運行速度至少提高5倍。

CrmConnection connection = new CrmConnection("XrmConnectionString"); // Todo: Replace magic connection string 
using (XrmVRC.XrmVrcServiceContext context = new XrmVRC.XrmVrcServiceContext(connection)) { 
    // Processing... 
} 
+0

完全這個答案一致。使用ServerConnection類時,我們的網站花費了2秒鐘時間來創建一個聯繫人記錄。使用CrmConnection需要5ms。我們正在使用CRM Online。 – 2014-09-19 23:58:26

0

我也張貼在我被帕特如下答覆上MS Forum這個問題。

While it is somewhat limited, there is some direction regarding the caching of service connectivity in the SDK: 

Performance Best Practises - Caching 

The two primary suggestions being to: 

    1. Cache the IServiceConfiguration class 
    2. Monitor your WCF security token and refresh it before it expires 

基於該建議,我嘗試使用API​​示例代碼中的以下類。請讓我知道,如果有人有反饋或對/錯/更好的建議。

就AppPool的管理而言,我仍然在尋找信息。


1. ManagedTokenOrganizationServiceProxy 
2. AutoRefreshSecurityToken 
3. DeviceIdManager 

我添加下面的連接字符串到Web.config中

<add name="XrmConnectionString" connectionString="ServiceUri=http://<MACHINE>:<PORTt>/<ORG>/XRMServices/2011/Organization.svc; Domain=<DOMAIN>; Username=<USERNAME>; Password=<PASSWORD>" /> 

然後創建下面的類來創建連接。

/// <summary>Provides server connection information.</summary> 
public class ServerConnection 
{ 
    private static readonly ILog log = LogManager.GetLogger(typeof(ServerConnection)); 

    #region Public methods 
    /// <summary> 
    /// Obtains the OrganizationServiceProxy connection for the target organization's 
    /// Uri and user login credentials from theconfiguration. 
    /// </summary> 
    public static OrganizationServiceProxy getServiceProxy() { 
     ManagedTokenOrganizationServiceProxy serviceProxy = null; 
     log.Debug("in getServiceProxy"); 
     try { 
      CrmConnection crmConnection = new CrmConnection("XrmConnectionString"); 
      serviceProxy = new ManagedTokenOrganizationServiceProxy(crmConnection.ServiceUri, crmConnection.ClientCredentials); 
      log.Debug("ManagedTokenOrganizationServiceProxy created = " + serviceProxy); 
      serviceProxy.EnableProxyTypes(); 
     } catch (Exception e) { 
      log.Fatal(e, e); 
      throw; 
     } 
     log.Debug("Returning serviceProxy"); 
     return serviceProxy; 
    } 

    #endregion 
} 

繼MVC代碼所消耗的連接:

public ActionResult Index() { 
    XrmVrcServiceContext context = null; 
    try { 
     context = new XrmVrcServiceContext(ServerConnection.getServiceProxy()); 
    } catch (Exception e) { 
     log.Error(e, e); 
     throw; 
    } 
    return View(context.new_XYZEntitySet.ToList()); 
} 
1

這是一個很老的問題,但對於其他人還在尋找有這個SDK Extensions for Microsoft Dynamics CRM 2011 and Microsoft Dynamics CRM Online的讀取。我相信這些擴展會爲您處理緩存/資源池。

對於OP原始問題的解決方案看看herehere。下面是從CRM SDK文檔上面鏈接報價:

爲Microsoft Dynamics CRM開發人員擴展提供以下功能:

  • 簡化的連接由CrmConnection類提供的Microsoft Dynamics CRM服務器(微軟.Xrm.Client)

  • 通過定製提供給代碼生成工具強類型的代碼生成(CrmSvcUtil.exe)

  • App.config中和的Web.config可配置用於使由所述CrmConfigurationManager類(Microsoft.Xrm.Client)通過由CachedOrganizationService類所提供的服務結果的高速緩存

  • 性能增強提供自定義擴展(Microsoft.Xrm.Client)

Portal開發人員指南使您能夠構建與Microsoft Dynamics CRM緊密集成的Web門戶。有關更多信息,請參閱Microsoft Dynamics CRM 2011門戶開發人員指南和Microsoft Dynamics CRM Online。本指南證明了以下功能:

  • 安全管理(Microsoft.Xrm.Portal)

  • 緩存管理(Microsoft.Xrm.Portal)

  • 內容管理(Microsoft.Xrm.Portal ,Microsoft.Xrm.Portal.Files,WebSiteCopy.exe)