zoukankan      html  css  js  c++  java
  • Dynamics CRM2016 查询数据的三种方式的性能对比

        之前写过一个博客,对非声明验证方式下连接组织服务的两种方式的性能进行了对比,但当时只是对比了实例化组织服务的时间,并没有对查询数据的时间进行对比,那有朋友也在我的博客中留言了反映了查询的时间问题,一直没时间做具体的测试,值此web api出现的时机,一并测下

        下方是我的测试demo,分别列出了获取组织服务需要的时间及查询所花时间,demo中是以查询一条用户记录的所有属性为例

         三种分别是1、CrmConnection

                           2、普通的方式(姑且这么叫吧,因为这是最常用的)

                           3、web api

     static void Main(string[] args)
            {
                string result = "";
                #region CrmConnection效率
                DateTime dt1 = DateTime.Now;
                OrganizationService org = new OrganizationService(new CrmConnection("crm"));
                DateTime dt8 = DateTime.Now;
                result = result + "CrmConnection实例服务时间 " + (dt8 - dt1).Milliseconds.ToString() + "
    ";
                Entity test = org.Retrieve("systemuser", new Guid("B3EB9804-6CD8-E511-9413-D04319595BED"), new Microsoft.Xrm.Sdk.Query.ColumnSet(true));
                DateTime dt2 = DateTime.Now;
                result = result + "CrmConnection查询时间 " + (dt2 - dt8).Milliseconds.ToString() + "
    ";
                #endregion
    
                #region 普通方式获取OrganizationService
                DateTime dt3 = DateTime.Now;
                ClientCredentials clientCredentials = new ClientCredentials();
                clientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential("administrator", "001", "skysoft");
                IOrganizationService organizationServiceProxy = new OrganizationServiceProxy(new Uri("http://crmhost/XRMServices/2011/Organization.svc"), null, clientCredentials, null);
                DateTime dt4 = DateTime.Now;
                result = result + "普通方式获取组织服务时间 " + (dt4 - dt3).Milliseconds.ToString() + "
    ";
                Entity test1 = organizationServiceProxy.Retrieve("systemuser", new Guid("B3EB9804-6CD8-E511-9413-D04319595BED"), new Microsoft.Xrm.Sdk.Query.ColumnSet(true));
                DateTime dt5 = DateTime.Now;
                result = result + "普通方式查询数据时间 " + (dt5 - dt4).Milliseconds.ToString() + "
    ";
                result = result + "普通方式查询数据总时间 " + (dt5 - dt3).Milliseconds.ToString() + "
    ";
    
                #endregion
    
                #region web api方式
                DateTime dt6 = DateTime.Now;
                HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://crmhost/api/data/v8.0/systemusers(B3EB9804-6CD8-E511-9413-D04319595BED)");
                req.Credentials = new NetworkCredential("administrator", "", "skysoft");
                req.Method = "Get";
                using (HttpWebResponse res = (HttpWebResponse)req.GetResponse())
                {
                    StreamReader read = new StreamReader(res.GetResponseStream());
                    string result1 = read.ReadToEnd();
                }
                DateTime dt7 = DateTime.Now;
                result = result + "web api查询时间 " + (dt7 - dt6).Milliseconds.ToString() + "
    ";
    
                #endregion
                Console.WriteLine(result);
                Console.ReadLine();
           }


        下图是测试结果,可以看出第1种方式获取组织服务确实比第二种快很多,但在查询具体数据时就会落后很多,所以综合下来半斤八两吧,没有明显的差距,但看第三种也就是web api,完虐前两种,孰优孰劣一目了然。






  • 相关阅读:
    BZOJ 2821: 作诗(Poetize)( 分块 )
    BZOJ 2440: [中山市选2011]完全平方数( 二分答案 + 容斥原理 + 莫比乌斯函数 )
    BZOJ 1058: [ZJOI2007]报表统计( 链表 + set )
    BZOJ 1034: [ZJOI2008]泡泡堂BNB( 贪心 )
    BZOJ 1016: [JSOI2008]最小生成树计数( kruskal + dfs )
    BZOJ 2329: [HNOI2011]括号修复( splay )
    BZOJ 3143: [Hnoi2013]游走( 高斯消元 )
    BZOJAC400题留念
    BZOJ 2982: combination( lucas )
    poj 3233
  • 原文地址:https://www.cnblogs.com/cl1024cl/p/6205816.html
Copyright © 2011-2022 走看看