繁体   English   中英

C#WinForms应用程序中的EWS性能

[英]EWS Performance in C# WinForms application

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

我遇到的问题如下:

一切正常,但当前需要20-25秒才能检索我的约会(= Outlook中的日历项),而需要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​​进行开发)的经验绝对为0,因此我想知道性能是否有空间,或者我想知道这是否正常? 我没有发现任何与EWS = SLOW相关的东西,所以我有点担心。

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

谢谢

最可能减慢您的代码速度的是

            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());

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM