EWS:更新系列中的事件时,设置操作对于属性无效

时间:2012-07-11 12:21:07

标签: exchangewebservices

我使用Microsoft的EWS API 1.2.1与Exchange Server 2007 SP1进行通信。当我尝试更新系列中的特定事件时,我总是得到错误:“设置操作对于属性无效”。下面的示例创建了一个成功的主复制,然后我绑定到此主复制并尝试更新系列中的第三个序列。这失败了......

this is the stack trace:

Microsoft.Exchange.WebServices.Data.ServiceResponseException was unhandled
Message=Set action is invalid for property.
Source=Microsoft.Exchange.WebServices
StackTrace:
  at Microsoft.Exchange.WebServices.Data.ServiceResponse.InternalThrowIfNecessary()
  at Microsoft.Exchange.WebServices.Data.ServiceResponse.ThrowIfNecessary()
  at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()

有人可以帮我解决这个问题吗?在此先感谢!!

下面是我找到的完整测试代码。

谢谢,最诚挚的问候!

迪米特里

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Exchange.WebServices.Data;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;

namespace EWS_testWithRecurrences
{
    class Program
    {


    static void Main(string[] args)
    {
        ExchangeService _service = new ExchangeService(ExchangeVersion.Exchange2007_SP1,    TimeZoneInfo.Utc);
        string ls_master = string.Empty;

        // SSL - security (for accademius sake)
        System.Net.ServicePointManager.ServerCertificateValidationCallback =
            delegate(Object obj, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
            {
                return true;
            };

        _service.Url = new Uri("https://exchangeserver/EWS/exchange.asmx");
        _service.Credentials =  new System.Net.NetworkCredential("username", "password", "domain");


        // Add master for accedemius sake
        Appointment app = new Appointment(_service);
        app.Subject = "Weekly on friday!";
        app.Start = new DateTime(2012, 7, 13, 10, 0,0);
        DayOfTheWeek[] days = new DayOfTheWeek [] { DayOfTheWeek.Friday };
        app.End = new DateTime(2012, 7, 13, 10, 0, 0).AddHours(2);
        app.Recurrence = new Recurrence.WeeklyPattern(app.Start.Date, 1, days);
        app.Recurrence.StartDate = app.Start.Date;
        app.Recurrence.NumberOfOccurrences = 10;
        // Save: works!
        app.Save();
        ls_master = app.Id.UniqueId;

        // Occurrence exception (bind to master) and change the 3rd series in the sequence
        Appointment occurrence = Appointment.BindToOccurrence(_service, new ItemId(ls_master),3);
        occurrence.Subject = "Urgent status update";
        occurrence.Start = new DateTime(2012, 7, 11, 14, 0, 0);
        occurrence.End = new DateTime(2012, 7, 11, 14, 0, 0).AddHours(2);
        occurrence.StartTimeZone = TimeZoneInfo.Utc;
        // Save ==> this fails!
        occurrence.Update(ConflictResolutionMode.AlwaysOverwrite);
    }
  }
}

1 个答案:

答案 0 :(得分:0)

我有一个相关的“修改过的事件正在交叉或重叠相邻事件”错误。

我认为这是因为在主复发开始之前无法设置修改后的出现开始(2012-07-13> 2012-07-11):

app.Start = new DateTime(2012, 7, 13, 10, 0,0);
...
occurrence.Start = new DateTime(2012, 7, 11, 14, 0, 0);

将其更改为:

occurrence.Start = occurrence.Start.AddHours(-6);

一切似乎都在起作用。

我认为您应该首先更改约会开始,然后更改它的第一次出现并删除最后一次。但我不确定你是否真的想要那个。添加一个非重复约会将更容易。