Reputation: 5442
Exchange and Time Zones are going to be the death of me.
My Exchange Server is located in EST (UTC -5). Version of Exchange is 2007 SP1. User is located in Paris France (UTC +2). If I try to create an appointment as an All Day Event, it will always span 2 days. Here is the request:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<ns2:MailboxCulture xmlns:ns2="http://schemas.microsoft.com/exchange/services/2006/types"
xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
>en-US</ns2:MailboxCulture>
<ns2:RequestServerVersion
xmlns:ns2="http://schemas.microsoft.com/exchange/services/2006/types"
xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
Version="Exchange2007_SP1"/>
<ns2:TimeZoneContext xmlns:ns2="http://schemas.microsoft.com/exchange/services/2006/types"
xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
<ns2:TimeZoneDefinition Id="Romance Standard Time"/>
</ns2:TimeZoneContext>
</soap:Header>
<soap:Body>
<CreateItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:ns2="http://schemas.microsoft.com/exchange/services/2006/types"
SendMeetingInvitations="SendToAllAndSaveCopy">
<SavedItemFolderId>
<ns2:DistinguishedFolderId Id="calendar"/>
</SavedItemFolderId>
<Items>
<ns2:CalendarItem>
<ns2:Subject>Test TZ</ns2:Subject>
<ns2:Body BodyType="Text"/>
<ns2:Start>2011-10-28T09:00:00Z</ns2:Start>
<ns2:End>2011-10-28T17:00:00Z</ns2:End>
<ns2:IsAllDayEvent>true</ns2:IsAllDayEvent>
<ns2:Location>Somewhere</ns2:Location>
</ns2:CalendarItem>
</Items>
</CreateItem>
</soap:Body>
</soap:Envelope>
NOTE: I have the Time Zone on my computer set to "(UTC+01:00) Brussels, Copenhagen, Madrid, Paris", although the computer is physically located in EST.
This is what Outlook displays, spanning 2 days.
If I retrieve the newly created calendar item from Exchange, it shows the following start and end date/times:
<t:Start>2011-10-28T00:00:00Z</t:Start>
<t:End>2011-10-29T00:00:00Z</t:End>
<t:IsAllDayEvent>true</t:IsAllDayEvent>
(Entire response can be found here)
I've tried various combinations of the start and end dates, but no matter what I do, I always get it spanning 2 days. If I run the same thing (without the tz context header) in EST, it will only span a single day.
Upvotes: 0
Views: 1773
Reputation: 5442
Ok, answering my own question here. Looks like the key is setting the meeting time zone.
<ns2:MeetingTimeZone>
<ns2:BaseOffset>-P0Y0M0DT2H0M0S</ns2:BaseOffset>
</ns2:MeetingTimeZone>
Since this was UTC +2, and the duration values must be positive, put the '-' on the "P". Since the TZ is "UTC +2", you subtract 2 to get UTC (hence then negative in the offset). If this was EST (UTC -5), then the BaseOffset would be P0Y0M0DT5H0M0S.
Hope this helps someone.
Full request looks like this:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<ns2:MailboxCulture xmlns:ns2="http://schemas.microsoft.com/exchange/services/2006/types"
xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
>en-US</ns2:MailboxCulture>
<ns2:RequestServerVersion
xmlns:ns2="http://schemas.microsoft.com/exchange/services/2006/types"
xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
Version="Exchange2007_SP1"/>
<ns2:TimeZoneContext xmlns:ns2="http://schemas.microsoft.com/exchange/services/2006/types"
xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
<ns2:TimeZoneDefinition Id="Romance Standard Time"/>
</ns2:TimeZoneContext>
</soap:Header>
<soap:Body>
<CreateItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:ns2="http://schemas.microsoft.com/exchange/services/2006/types"
SendMeetingInvitations="SendToAllAndSaveCopy">
<SavedItemFolderId>
<ns2:DistinguishedFolderId Id="calendar"/>
</SavedItemFolderId>
<Items>
<ns2:CalendarItem>
<ns2:Subject>Test TZ</ns2:Subject>
<ns2:Body BodyType="Text"/>
<ns2:Start>2011-10-27T22:00:00Z</ns2:Start>
<ns2:End>2011-10-28T22:00:00Z</ns2:End>
<ns2:IsAllDayEvent>true</ns2:IsAllDayEvent>
<ns2:Location>Somewhere</ns2:Location>
<ns2:MeetingTimeZone>
<ns2:BaseOffset>-P0Y0M0DT2H0M0S</ns2:BaseOffset>
</ns2:MeetingTimeZone>
</ns2:CalendarItem>
</Items>
</CreateItem>
</soap:Body>
</soap:Envelope>
Upvotes: 2