我也張貼在我被帕特如下答覆上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());
}
完全這個答案一致。使用ServerConnection類時,我們的網站花費了2秒鐘時間來創建一個聯繫人記錄。使用CrmConnection需要5ms。我們正在使用CRM Online。 – 2014-09-19 23:58:26