【问题标题】:EWS Performance in C# WinForms applicationC# WinForms 应用程序中的 EWS 性能
【发布时间】:2019-01-30 10:36:59
【问题描述】:

我在我的 winforms 应用程序中使用 EWS 在我的 Outlook 中创建一个新约会(+ 以从我的 Outlook 日历中获取项目)。

我遇到的问题如下:

一切正常,但目前检索我的约会(= Outlook 中的日历项目)需要 20-25 秒,创建约会需要 13-20 秒

执行此操作的代码直接来自“Google”:

 private void btn_Test_Click(object sender, EventArgs e)
        {
            DateTime d1 = DateTime.Now;
            ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallBack;
            try
            {
            service = new ExchangeService(ExchangeVersion.Exchange2013);
                service.Credentials = new WebCredentials("mail", "pass");
                /*service.TraceEnabled = true;
                service.TraceFlags = TraceFlags.All;*/
                service.AutodiscoverUrl("mail", RedirectionUrlValidationCallback);
                service.Url = new Uri("https://mail.domain.com/EWS/Exchange.asmx");
            }
            catch (Exception ml2)
            {
                MessageBox.Show(ml2.ToString());
            }

        // We get 10 items in the calendar for the next week
            DateTime startDate = DateTime.Now;
            DateTime endDate = startDate.AddDays(7);
            const int NUM_APPTS = 10;
            // Initialize the calendar folder object with only the folder ID. 
            CalendarFolder calendar = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, new PropertySet());
            // Set the start and end time and number of appointments to retrieve.
            CalendarView cView = new CalendarView(startDate, endDate, NUM_APPTS);
            // Limit the properties returned to the appointment's subject, start time, and end time.
            cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End);
            // Retrieve a collection of appointments by using the calendar view.
            FindItemsResults<Appointment> appointments = calendar.FindAppointments(cView);
            Console.WriteLine("\nThe first " + NUM_APPTS + " appointments on your calendar from " + startDate.Date.ToShortDateString() +
                              " to " + endDate.Date.ToShortDateString() + " are: \n");

            foreach (Appointment a in appointments)
            {
                Console.Write("Subject: " + a.Subject.ToString() + " ");
                Console.Write("Start: " + a.Start.ToString() + " ");
                Console.Write("End: " + a.End.ToString());
                Console.WriteLine();
            }

       DateTime d2 = DateTime.Now;
           MessageBox.Show( "Seconds: " + (d2 - d1).TotalSeconds.ToString());
        }

由于我在 EWS 方面的经验绝对为零(或在使用 API 时进行开发),我想知道是否还有性能空间,或者我想知道这是否正常?我没有发现任何与 EWS = SLOW 相关的东西,所以我有点担心。

可能是我的代码有误,或者我需要配置一件事或另一台服务器端来改善结果?

谢谢

【问题讨论】:

    标签: c# .net winforms exchangewebservices


    【解决方案1】:

    最有可能让你的代码变慢的是

                service.AutodiscoverUrl("mail", RedirectionUrlValidationCallback);
                service.Url = new Uri("https://mail.domain.com/EWS/Exchange.asmx");
    

    您执行自动发现,然后手动设置链接,这会使第一个自动发现调用变得多余。自动发现将对本地 AD 域、DNS 记录进行多次搜索,以尝试发现要使用的正确 URL,因此我建议您是否要对您在第一行注释掉的 URL 进行硬编码。

    此外,您的测试逻辑仅查看执行功能的总时间,这不会有帮助,您应该查看完成每个操作的时间,例如

    FindItemsResults<Appointment> appointments = calendar.FindAppointments(cView);
    

    CalendarFolder calendar = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, new PropertySet());
    

    或在实际调用服务器时调用任何保存、发送类型的方法调用,如果您对此进行计时,这将为您提供每次调用速度的真实指示。

    【讨论】:

      猜你喜欢
      • 2010-10-11
      • 1970-01-01
      • 1970-01-01
      • 2012-01-20
      • 1970-01-01
      • 2011-01-21
      • 1970-01-01
      • 2010-10-22
      • 1970-01-01
      相关资源
      最近更新 更多