XRM/Dynamics CRM 2011 中 OrganizationServiceProxy 的连接/对象池

发布于 2024-11-01 04:28:18 字数 424 浏览 3 评论 0原文

我正在编写一个 MVC 3 WebApp,它使用 Early Bound 使用 XRM 2011。这是一个面向 Internet 的应用程序,托管在与 Dynamics IIS 不同的计算机上。

这当然使得 OrganizationServiceProxy 调用非常非常频繁,并且每次第一次点击时响应都有点迟缓。

是否建议重用 OrganizationServiceProxy 连接而不是每次都创建新实例?

如果是,

  1. 是否有任何东西可以管理连接,例如
    • 连接池应用 - MS 或第三方/开源
    • 或者像WCF这样的框架(还没有使用过WCF)
  2. 如果我必须编写自己的代码来管理连接,建议使用哪种设计模式?

很抱歉 MS 网站上有重复的帖子。希望这个论坛更加活跃。

I am writing a MVC 3 WebApp which uses XRM 2011 using Early Bound. This is an internet-facing application hosted on separate machine than Dynamics IIS.

This of course makes OrganizationServiceProxy call very very frequently and response is kind of sluggish on every first hit.

Is it advisable to reuse OrganizationServiceProxy connection rather than create new instance every time?

If yes,

  1. Is there anything to manage the connections such as
    • connection pool app - MS or third party/open source
    • or some framework like WCF (Never used WCF, yet)
  2. Which design pattern is recommended if I have to write my own code to manage connection?

Sorry for the duplicate post from MS website. Hopefully this forum is more active.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

℡Ms空城旧梦 2024-11-08 04:28:18

经过几个测试周期,我发现使用 CrmConection 是最快的方法。与上述缓存实现相比,CrmConnection 的运行速度至少快 5 倍。

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

After few test cycles, I have found that using CrmConection is the fastest method. Compared to above caching implementation, CrmConnection runs at least 5 times faster.

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

这是一个相当老的问题,但对于仍在寻找的其他人来说,请阅读此 SDK Microsoft Dynamics CRM 2011 和 Microsoft Dynamics CRM Online 的扩展。我相信扩展会为您处理资源的缓存/池化。

有关OP原始问题的解决方案,请查看 此处此处。以下是上面链接的 CRM SDK 文档的引用:

Microsoft Dynamics CRM 开发人员扩展提供以下功能:

  • CrmConnection 类 (Microsoft.Xrm.Client) 提供的与 Microsoft Dynamics CRM 服务器的简化连接

  • 通过自定义代码生成工具 (CrmSvcUtil.exe) 提供强类型的代码生成

  • App.config 和 Web.config 可配置性,用于启用 CrmConfigurationManager 类 (Microsoft.Xrm.Client) 提供的自定义扩展

  • 通过缓存 CachedOrganizationService 类 (Microsoft.Xrm.Client) 提供的服务结果来增强性能

门户开发人员指南使您能够构建与 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)

This is quite an old question but for anyone else still looking have a read of this SDK Extensions for Microsoft Dynamics CRM 2011 and Microsoft Dynamics CRM Online. I believe the extensions take care of the caching/pooling of resources for you.

For a solution to OP original question have a look here and here. Below is a quote from the CRM SDK documentation linked above:

Developer Extensions for Microsoft Dynamics CRM provide the following capabilities:

  • Simplified connection to Microsoft Dynamics CRM servers provided by the CrmConnection class (Microsoft.Xrm.Client)

  • Code Generation of strong types provided by customizations to the code generation tool (CrmSvcUtil.exe)

  • App.config and Web.config configurability for enabling custom extensions provided by the CrmConfigurationManager class (Microsoft.Xrm.Client)

  • Performance enhancements through caching of service results provided by the CachedOrganizationService class (Microsoft.Xrm.Client)

The Portal Developer’s Guide enables you to build a Web portal that is tightly integrated with Microsoft Dynamics CRM. For more information, see Portal Developer Guide for Microsoft Dynamics CRM 2011 and Microsoft Dynamics CRM Online. This guide proves the following capabilities:

  • Security Management (Microsoft.Xrm.Portal)

  • Cache Management (Microsoft.Xrm.Portal)

  • Content Management (Microsoft.Xrm.Portal, Microsoft.Xrm.Portal.Files, WebSiteCopy.exe)

余罪 2024-11-08 04:28:18

我还在 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());
}

I also posted this question on MS Forum where I got following reply by 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 

Based on that advise, I endedup using following classes from the API sample code. Please let me know if anyone has feedback or right/wrong/better advise on this.

As far management of AppPool is concerned, I still looking for info.


1. ManagedTokenOrganizationServiceProxy
2. AutoRefreshSecurityToken
3. DeviceIdManager

I added following connection string to web.config

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

Then I created following class to create connection.

/// <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
}

Following MVC code consumes the connection:

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());
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文