Search code examples
c#exchangewebservices

The required attribute 'BodyType' is missing when calling Appointment.Bind(service, new ItemId(AppointmentID))


When calling

Appointment appt = Appointment.Bind(service, new ItemId(AppointmentID));

I get The request failed schema validation:

 The required attribute 'BodyType' is missing.

   at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ProcessWebException(WebException webException) in \\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\Requests\ServiceRequestBase.cs:line 990
   at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest request) in \\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\Requests\ServiceRequestBase.cs:line 831
   at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(IEwsHttpWebRequest& request) in \\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\Requests\ServiceRequestBase.cs:line 724
   at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute() in \\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\Requests\MultiResponseServiceRequest.cs:line 157
   at Microsoft.Exchange.WebServices.Data.ExchangeService.BindToItem(ItemId itemId, PropertySet propertySet) in \\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\ExchangeService.cs:line 1281
   at Microsoft.Exchange.WebServices.Data.ExchangeService.BindToItem[TItem](ItemId itemId, PropertySet propertySet) in \\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\ExchangeService.cs:line 1299

I'm keeping the AppointmentID in another database for tracking. And I would expect a different type of error if the appointment is not found.

I expect the appt to load without any error

More code:

private void CancelAppointment(string AppointmentID)
{
    try
    {
        ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1, TimeZoneInfo.Utc);
        ExchangeConnectionInfo ConnectInfo = null;
        ConnectInfo = new ExchangeConnectionInfo(_mUserId);
        ConnectToService();

        var userEmail = ConnectInfo.GetUserEmail();
        service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, userEmail);

        Appointment appt = Appointment.Bind(service, new ItemId(AppointmentID));

        appt.Delete(DeleteMode.HardDelete, SendCancellationsMode.SendOnlyToAll);
    }
    catch (Exception e)
    {
        ErrorLog.Log("ExchangeIntegrationWS", "CancelAppointmentError", e.Message + "\n\n" + e.StackTrace);
    }
}

Solution

  • I'm not sure exactly why your getting the error. I'm guessing maybe there is a bug with the old exchange version you are using.

    Anyway, I think If you change the Appointment.Bind code to include a propertySet parameter and instruct EWS to return the body, that should fix the error.

    Appointment appt = Appointment.Bind(service, new ItemId(AppointmentID), new PropertySet(BasePropertySet.FirstClassProperties) { RequestedBodyType = BodyType.Text});