首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Update()上设置属性时如何设置Microsoft.Exchange.WebServices.Data.Appointment?

在Update()上设置属性时如何设置Microsoft.Exchange.WebServices.Data.Appointment?
EN

Stack Overflow用户
提问于 2016-12-29 19:47:00
回答 1查看 1.1K关注 0票数 4

问题

我有一个带有Microsoft.Exchange.WebServices v2.2.0 NuGet包的VisualStudio2015控制台应用程序。我正在尝试创建一个约会,更新它,并取消它,同时在日历invite 中自动生成的"When“字符串中保留正确的Timezone。当前,初始创建具有正确的时区,但是任何后续更新都会导致时区恢复到UTC。

注意:我们有一个Exchange 2010服务器,并使用Outlook 2013客户端。

代码样本

代码语言:javascript
复制
using System;
using System.Globalization;
using Microsoft.Exchange.WebServices.Data;

namespace EWSTesting
{
    class Program
    {
        private const string EmailServer = ""; //replace with your Exchange server
        private const string EmailAddress = ""; //replace with your email

        static void Main(string[] args)
        {
            Console.WriteLine("Current Timezone: " + TimeZoneInfo.Local.DisplayName);

            var exchangeService = new ExchangeService(ExchangeVersion.Exchange2010, TimeZoneInfo.Local)
            {
                PreferredCulture = new CultureInfo("en-US"),
                Url = new Uri(EmailServer),
                UseDefaultCredentials = true
            };

            Console.WriteLine("exchangeService.TimeZone.DisplayName: " + exchangeService.TimeZone.DisplayName);

            var startDate = DateTime.Today;
            var endDate = startDate.AddHours(1);

            //Create initial appointment
            var appointment = new Appointment(exchangeService)
            {
                Subject = "Testing Appointments",
                Body = "Testing Appointments Body",
                Location = "Test Location",
                LegacyFreeBusyStatus = LegacyFreeBusyStatus.Busy,
                Sensitivity = Sensitivity.Private,
                Start = startDate,
                End = endDate
            };
            appointment.OptionalAttendees.Add(EmailAddress);
            appointment.Save(SendInvitationsMode.SendOnlyToAll);

            Console.WriteLine("exchangeService.TimeZone.DisplayName: " + exchangeService.TimeZone.DisplayName);

            var appointmentId = appointment.Id;

            Console.WriteLine("Pause to check inbox 'When' value on invite");
            Console.ReadLine();

            appointment = Appointment.Bind(exchangeService, appointmentId);

            appointment.Load(new PropertySet(PropertySet.FirstClassProperties)
            {
                AppointmentSchema.StartTimeZone,
                AppointmentSchema.EndTimeZone,
                AppointmentSchema.TimeZone
            });

            appointment.Body = "Body Updated Successfully";
            appointment.Update(ConflictResolutionMode.AlwaysOverwrite, SendInvitationsOrCancellationsMode.SendOnlyToAll);

            Console.WriteLine("exchangeService.TimeZone.DisplayName: " + exchangeService.TimeZone.DisplayName);
            Console.WriteLine("appointment.StartTimeZone.DisplayName: " + appointment.StartTimeZone.DisplayName);
            Console.WriteLine("appointment.EndTimeZone.DisplayName: " + appointment.EndTimeZone.DisplayName);
            Console.WriteLine("appointment.TimeZone: " + appointment.TimeZone);

            Console.WriteLine();
            Console.WriteLine("Pause to check updated inbox 'When' value on invite");
            Console.ReadLine();

            appointment = Appointment.Bind(exchangeService, appointmentId);

            appointment.Load(new PropertySet(PropertySet.FirstClassProperties)
            {
                AppointmentSchema.StartTimeZone,
                AppointmentSchema.EndTimeZone,
                AppointmentSchema.TimeZone
            });

            Console.WriteLine("exchangeService.TimeZone.DisplayName: " + exchangeService.TimeZone.DisplayName);
            Console.WriteLine("appointment.StartTimeZone.DisplayName: " + appointment.StartTimeZone.DisplayName);
            Console.WriteLine("appointment.EndTimeZone.DisplayName: " + appointment.EndTimeZone.DisplayName);
            Console.WriteLine("appointment.TimeZone: " + appointment.TimeZone);

            appointment.CancelMeeting();

            Console.WriteLine("Appointment Deleted");
            Console.ReadLine();
        }
    }
}

上述代码的结果

初始邀请(正确的时区)

更新任命(正文中不正确的时区)

取消约会(正文中不正确的时区)

所提供代码的控制台结果

我在找什么

我不需要这个额外的“时”(在上面的图片红色下划线)被附加到邀请的主体。要么我想完全删除它(首选),要么我想在任何更新中纠正它。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-01-18 18:13:01

这个问题似乎是EWS2.2.0DLL中的一个缺陷,时区SOAP头没有添加到更新()和CancelMeeting() Exchange事务中。下面的代码通过手动追加正确的头来解决此问题。

最新消息():

代码语言:javascript
复制
exchangeService.OnSerializeCustomSoapHeaders += service_OnSerializeCustomSoapHeaders;
appointment.Update(ConflictResolutionMode.AlwaysOverwrite, SendInvitationsOrCancellationsMode.SendOnlyToAll);
exchangeService.OnSerializeCustomSoapHeaders -= service_OnSerializeCustomSoapHeaders;

对于CancelMeeting():

代码语言:javascript
复制
exchangeService.OnSerializeCustomSoapHeaders += service_OnSerializeCustomSoapHeaders;
appointment.CancelMeeting();
exchangeService.OnSerializeCustomSoapHeaders -= service_OnSerializeCustomSoapHeaders;

活动执行情况:

代码语言:javascript
复制
static void service_OnSerializeCustomSoapHeaders(XmlWriter writer)
{
    writer.WriteRaw(Environment.NewLine + "    <t:TimeZoneContext><t:TimeZoneDefinition Id=\"" + TimeZoneInfo.Local.StandardName + "\"/></t:TimeZoneContext>" + Environment.NewLine);
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41386268

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档