编程语言
首页 > 编程语言> > c# – EWS – 尝试加载与会者时列出日历约会失败

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

作者:互联网

我试图使用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
        );

其中一个事件我们收到以下错误.如果我从AppointmentPropertySet中删除RequiredAttendees和OptionalAttendees,它可以正常工作(虽然没有返回参加者).

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

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

解决方法:

根据异常堆栈跟踪判断,我很确定您的Exchange服务器正在使用无效值(“User”)回复一个(或多个)与会者电子邮件地址的MailboxType.

看看current implementation of the MailboxType enum,即使使用最新版本,“用户”的值也似乎无效.

您应该能够通过跟踪Exchange返回给您的肥皂响应,通过跟踪它(参见How to: Trace requests and responses to troubleshoot EWS Managed API applications)或使用像Fiddler或Wireshark这样的网络分析器来进一步确认这一点.

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

标签:c,exchangewebservices,ews-managed-api
来源: https://codeday.me/bug/20190701/1348921.html