Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exchange Web Services Create Meeting Request Working Example

Is there a working example anywhere of how to create a meeting request using EWS for Exchange 2007 using C#? Which properties are required? I have added a web service reference and can connect to create and send various items but keep getting the error "Set action is invalid for property." on the response messages. It never says what property is invalid

var ews = new ExchangeServiceBinding {
    Credentials = new NetworkCredential("user", "pass"),
    Url = "https://servername/ews/exchange.asmx", 
    RequestServerVersionValue = new RequestServerVersion {
        Version = ExchangeVersionType.Exchange2007}
};
var startDate = new DateTime(2010, 9, 18, 16, 00, 00);
var meeting = new CalendarItemType {
    IsMeeting = true,
    IsMeetingSpecified = true,
    Subject = "test EWS",
    Body = new BodyType {Value = "test body", BodyType1 = BodyTypeType.HTML},
    Start = startDate,
    StartSpecified = true,
    End = startDate.AddHours(1),
    EndSpecified = true,
    MeetingTimeZone = new TimeZoneType{
        TimeZoneName = TimeZone.CurrentTimeZone.StandardName, BaseOffset = "PT0H"},
    Location = "Meeting",
    RequiredAttendees = new [] {
        new AttendeeType{Mailbox =new EmailAddressType{
                         EmailAddress ="[email protected]",RoutingType = "SMTP"}},
        new AttendeeType{Mailbox =new EmailAddressType{
                         EmailAddress ="[email protected]",RoutingType = "SMTP"}}
    }
};
var request = new CreateItemType {
    SendMeetingInvitations =
        CalendarItemCreateOrDeleteOperationType.SendToAllAndSaveCopy,
    SendMeetingInvitationsSpecified = true,
    SavedItemFolderId = new TargetFolderIdType{Item = new DistinguishedFolderIdType{
                                        Id=DistinguishedFolderIdNameType.calendar}},
    Items = new NonEmptyArrayOfAllItemsType {Items = new ItemType[] {meeting}}
};
CreateItemResponseType response = ews.CreateItem(request);
var responseMessage = response.ResponseMessages.Items[0];

Microsoft provides an XML example at http://msdn.microsoft.com/en-us/library/aa494190(EXCHG.140).aspx of what the message item should look like. Just setting these properties does not seem to be enough. Can someone tell me what I'm missing or point me to some better examples or documentation?

<CreateItem
       xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
       SendMeetingInvitations="SendToAllAndSaveCopy" >
  <SavedItemFolderId>
    <t:DistinguishedFolderId Id="calendar"/>
  </SavedItemFolderId>
  <Items>
    <t:CalendarItem>
      <t:Subject>Meeting with attendee0, attendee1, attendee2</t:Subject>
      <t:Body BodyType="Text">CalendarItem:TextBody</t:Body>
      <t:Start>2006-06-25T10:00:00Z</t:Start>
      <t:End>2006-06-25T11:00:00Z</t:End>
      <t:Location>CalendarItem:Location</t:Location>
      <t:RequiredAttendees>
        <t:Attendee>
          <t:Mailbox>
            <t:EmailAddress>[email protected]</t:EmailAddress>
          </t:Mailbox>
        </t:Attendee>
        <t:Attendee>
          <t:Mailbox>
            <t:EmailAddress>[email protected]</t:EmailAddress>
          </t:Mailbox>
        </t:Attendee>
      </t:RequiredAttendees>
      <t:OptionalAttendees>
        <t:Attendee>
          <t:Mailbox>
            <t:EmailAddress>[email protected]</t:EmailAddress>
          </t:Mailbox>
        </t:Attendee>
      </t:OptionalAttendees>
      <t:Resources>
        <t:Attendee>
          <t:Mailbox>
            <t:EmailAddress>[email protected]</t:EmailAddress>
          </t:Mailbox>
        </t:Attendee>
      </t:Resources>
    </t:CalendarItem>
  </Items>
</CreateItem>
like image 405
Tion Avatar asked Oct 26 '22 06:10

Tion


1 Answers

This is probably too late for you, but this for anyone else trying this.

The issue seems to be with providing the Is-Specified params. I deleted the IsMeetingSpecified and the request worked. Here's the revised CalendarItemType.

var meeting = new CalendarItemType
{
    IsMeeting = true,
    Subject = "test EWS",
    Body = new BodyType { Value = "test body", BodyType1 = BodyTypeType.HTML },
    Start = startDate,
    StartSpecified = true,
    End = startDate.AddHours(1),
    EndSpecified = true,
    MeetingTimeZone = new TimeZoneType
    {
        TimeZoneName = TimeZone.CurrentTimeZone.StandardName,
        BaseOffset = "PT0H"
    },
    Location = "Room 1",
    RequiredAttendees = new[] {
        new AttendeeType
        {
            Mailbox =new EmailAddressType
            {     
                EmailAddress ="[email protected]"
            }
        },
    }
};
like image 66
Erik Elkins Avatar answered Oct 31 '22 00:10

Erik Elkins