EWS - 尝试加载与会者时列出日历约会失败

时间:2017-09-19 14:51:56

标签: c# exchangewebservices ews-managed-api

我正在尝试使用C#EWS 2.0库列出一些事件。

使用以下代码:

    public IEnumerable<AppEvent> ListEvents(CalendarFolder folder, DateTime? startDate, DateTime? endDate)
    {
        var items = new List<AppEvent>();

        var now = DateTime.Now;
        if (startDate == null) startDate = DateTime.Now;
        if (endDate == null) endDate = now.AddDays(14);

        FindItemsResults<Appointment> findResults = null;
        ServiceResponseCollection<GetItemResponse> appointments = null;
        CalendarView view = null;

        view = new CalendarView((DateTime)startDate, (DateTime)endDate);
        findResults = folder.FindAppointments(view);

        if (findResults.Items.Count() == 0) return items;
        appointments = Service.BindToItems(findResults.Select(item => item.Id), AppointmentPropertySet);

        foreach (GetItemResponse item in appointments)
        {
            var appointment = item.Item as Appointment;
            try
            {
                if (appointment.IsCancelled) continue;
            }
            catch (System.NullReferenceException)
            {
                continue;
            }
            var evt = AppEvent.FromEWSAppointment(appointment);
            items.Add(evt);
        }

        return items;
    }

AppointmentPropertySet如下:

    protected PropertySet AppointmentPropertySet = new PropertySet(
        AppointmentSchema.Subject, 
        AppointmentSchema.Start,
        AppointmentSchema.End, 
        AppointmentSchema.IsAllDayEvent, 
        AppointmentSchema.IsMeeting,
        AppointmentSchema.IsRecurring, 
        AppointmentSchema.IsCancelled,
        AppointmentSchema.IsDraft, 
        AppointmentSchema.Location,
        AppointmentSchema.Resources,
        AppointmentSchema.RequiredAttendees, 
        AppointmentSchema.OptionalAttendees,
        AppointmentSchema.LegacyFreeBusyStatus,
        AppointmentSchema.Organizer, 
        AppointmentSchema.Body,
        AppointmentSchema.Sensitivity,
        AppointmentSchema.AppointmentReplyTime,
        AppointmentSchema.AppointmentSequenceNumber,
        AppointmentSchema.AppointmentState,
        AppointmentSchema.AppointmentType,
        AppointmentSchema.ConferenceType,
        AppointmentSchema.DateTimeCreated,
        AppointmentSchema.Duration,
        AppointmentSchema.EndTimeZone,
        AppointmentSchema.HasAttachments,
        AppointmentSchema.ICalDateTimeStamp,
        AppointmentSchema.ICalRecurrenceId,
        AppointmentSchema.ICalUid,
        AppointmentSchema.Id,
        AppointmentSchema.Importance,
        AppointmentSchema.IsOnlineMeeting,
        AppointmentSchema.IsReminderSet,
        AppointmentSchema.IsResponseRequested,
        AppointmentSchema.IsUnmodified,
        AppointmentSchema.LastModifiedTime,
        AppointmentSchema.LegacyFreeBusyStatus,
        AppointmentSchema.MeetingRequestWasSent,
        AppointmentSchema.MyResponseType,
        AppointmentSchema.MeetingWorkspaceUrl,
        AppointmentSchema.NetShowUrl,
        AppointmentSchema.OriginalStart,
        AppointmentSchema.ParentFolderId,
        AppointmentSchema.Recurrence,
        AppointmentSchema.ReminderDueBy,
        AppointmentSchema.ReminderMinutesBeforeStart,
        AppointmentSchema.StartTimeZone,
        AppointmentSchema.WebClientEditFormQueryString,
        AppointmentSchema.WebClientReadFormQueryString
        );

我们收到其中一个事件的以下错误。如果我从RequiredAttendees中移除OptionalAttendeesAppointmentPropertySet,则可以正常使用(虽然不会返回任何与会者)。

如何避免此错误,或者如何跳过此事件以使视图至少返回未损坏的约会?

System.ArgumentException: Requested value 'User' was not found.
   at System.Enum.EnumResult.SetFailure(ParseFailureKind failure, String failureMessageID, Object failureMessageFormatArgument)
   at System.Enum.TryParseEnum(Type enumType, String value, Boolean ignoreCase, EnumResult& parseResult)
   at System.Enum.Parse(Type enumType, String value, Boolean ignoreCase)
   at Microsoft.Exchange.WebServices.Data.EwsUtilities.Parse[T](String value)
   at Microsoft.Exchange.WebServices.Data.EwsXmlReader.ReadElementValue[T]()
   at Microsoft.Exchange.WebServices.Data.EmailAddress.TryReadElementFromXml(EwsServiceXmlReader reader)
   at Microsoft.Exchange.WebServices.Data.Attendee.TryReadElementFromXml(EwsServiceXmlReader reader)
   at Microsoft.Exchange.WebServices.Data.ComplexProperty.InternalLoadFromXml(EwsServiceXmlReader reader, XmlNamespace xmlNamespace, String xmlElementName, Func`2 readAction)
   at Microsoft.Exchange.WebServices.Data.ComplexProperty.LoadFromXml(EwsServiceXmlReader reader, XmlNamespace xmlNamespace, String xmlElementName)
   at Microsoft.Exchange.WebServices.Data.Attendee.TryReadElementFromXml(EwsServiceXmlReader reader)
   at Microsoft.Exchange.WebServices.Data.ComplexProperty.InternalLoadFromXml(EwsServiceXmlReader reader, XmlNamespace xmlNamespace, String xmlElementName, Func`2 readAction)
   at Microsoft.Exchange.WebServices.Data.ComplexProperty.LoadFromXml(EwsServiceXmlReader reader, XmlNamespace xmlNamespace, String xmlElementName)
   at Microsoft.Exchange.WebServices.Data.ComplexPropertyCollection`1.LoadFromXml(EwsServiceXmlReader reader, XmlNamespace xmlNamespace, String localElementName)
   at Microsoft.Exchange.WebServices.Data.ComplexPropertyDefinitionBase.InternalLoadFromXml(EwsServiceXmlReader reader, PropertyBag propertyBag)
   at Microsoft.Exchange.WebServices.Data.ComplexPropertyDefinitionBase.LoadPropertyValueFromXml(EwsServiceXmlReader reader, PropertyBag propertyBag)
   at Microsoft.Exchange.WebServices.Data.PropertyBag.LoadFromXml(EwsServiceXmlReader reader, Boolean clear, PropertySet requestedPropertySet, Boolean onlySummaryPropertiesRequested)
   at Microsoft.Exchange.WebServices.Data.EwsServiceXmlReader.ReadServiceObjectsCollectionFromXml[TServiceObject](XmlNamespace collectionXmlNamespace, String collectionXmlElementName, GetObjectInstanceDelegate`1 getObjectInstanceDelegate, Boolean clearPropertyBag, PropertySet requestedPropertySet, Boolean summaryPropertiesOnly)
   at Microsoft.Exchange.WebServices.Data.GetItemResponse.ReadElementsFromXml(EwsServiceXmlReader reader)
   at Microsoft.Exchange.WebServices.Data.ServiceResponse.LoadFromXml(EwsServiceXmlReader reader, String xmlElementName)
   at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.ParseResponse(EwsServiceXmlReader reader)
   at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ReadResponse(EwsServiceXmlReader ewsXmlReader)
   at Microsoft.Exchange.WebServices.Data.SimpleServiceRequestBase.ReadResponseXml(Stream responseStream)
   at Microsoft.Exchange.WebServices.Data.SimpleServiceRequestBase.ReadResponse(IEwsHttpWebResponse response)
   at Microsoft.Exchange.WebServices.Data.ExchangeService.InternalBindToItems(IEnumerable`1 itemIds, PropertySet propertySet, ServiceErrorHandling errorHandling)
   at ExchangeAppService.Utilities.API.ExchangeAPI.ListEvents(CalendarFolder folder, Nullable`1 startDate, Nullable`1 endDate) in c:\Users\Some Guy\Documents\Visual Studio 2013\Projects\ExchangeAppService\ExchangeAppService\Utilities\API\Exchange\ExchangeAPI.cs:line 195

2 个答案:

答案 0 :(得分:2)

根据异常堆栈跟踪判断,我非常确定您的Exchange服务器正在使用无效值(&#34;用户&#34;)回复一个(或多个)与会者电子邮件的邮箱类型地址。

current implementation of the MailboxType enum它似乎是价值&#34;用户&#34;即使使用最新版本也无效。

您应该能够通过分析Exchange返回给您的soap响应,通过跟踪它(请参阅How to: Trace requests and responses to troubleshoot EWS Managed API applications)或使用Fiddler或Wireshark等网络分析器来进一步确认。

如果是这种情况,我认为唯一的解决方案是在github repo上打开一个问题,并希望他们能为您提供更多信息或解决您的问题。

答案 1 :(得分:0)

2017年12月15日在github上发布了一个问题。 https://github.com/OfficeDev/ews-managed-api/issues/145

尚未回复。我们已经开始在约30%的客户邮箱中遇到同样的问题,我们担心这会传播