また、この質問をMSフォーラムに投稿し、Patからの返信を受け取りました。
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());
}