다음을 통해 공유


Specifying the time zone when creating items by using the EWS Managed API 2.0

Last modified: January 23, 2013

Applies to: EWS Managed API | Exchange Server 2007 Service Pack 1 (SP1) | Exchange Server 2010

Note: This content applies to the EWS Managed API 2.0 and earlier versions. For the latest information about the EWS Managed API, see Web services in Exchange.

You can use the Exchange Web Services (EWS) Managed API to specify the time zone for DateTime properties when you create items. The process for specifying the time zone for a calendar item differs slightly based on whether you are using the EWS Managed API against versions of Exchange starting with Exchange Server 2010, including Exchange Online, or Exchange Server 2007 Service Pack 1 (SP1).

Note

For more information about time zones, see Time zones in the EWS Managed API 2.0.

To specify the local time zone for a calendar item when you are using versions of Exchange starting with Exchange 2010

  • Instantiate the ExchangeService object without specifying the time zone, as shown in the following code, and do not set the StartTimeZone property and EndTimeZone property on the calendar item. The EWS Managed API will use the computer's local time zone as the default time zone context for the DateTime properties of the calendar item that is created by using the ExchangeService object.

    ExchangeService service = new ExchangeService();
    

    Or

    Set the StartTimeZone property and the EndTimeZone property to TimeZoneInfo.Local on the calendar item. Setting these properties will specify the local time zone for the start time, reminder due by time, and end time of the calendar item, regardless of the time zone on the ExchangeService that is used to create the item. In the following code example, the local time zone is specified for the appointment's StartTimeZone and EndTimeZone.

    appointment.StartTimeZone = TimeZoneInfo.Local;
    appointment.EndTimeZone = TimeZoneInfo.Local;
    

To specify the local time zone for a calendar item when you are using Exchange 2007 SP1

  • Set the StartTimeZone property to TimeZoneInfo.Local on the calendar item. In the following code example, the local time zone is specified for the appointment's StartTimeZone.

    appointment.StartTimeZone = TimeZoneInfo.Local;
    

    Note

    If you instantiate the ExchangeService object without specifying the time zone, and do not set the StartTimeZone property on the calendar item, all DateTime properties on the calendar item will be scoped to Coordinated Universal Time (UTC).

To specify the local time zone for a non-calendar item

  • Instantiate the ExchangeService object without specifying the time zone, as shown in the following code. If you do not specify a time zone, the EWS Managed API will use the computer's local time zone as the default time zone context for all DateTime properties of non-calendar items that are created by using the ExchangeService.

    ExchangeService service = new ExchangeService();
    

To specify a non-local time zone for a calendar item when you are using versions of Exchange starting with Exchange 2010

  • Specify the non-local time zone when you instantiate the ExchangeService object that will be used to create the calendar item, and do not set the StartTimeZone property and EndTimeZone property on the calendar item. The time zone that is specified when the ExchangeService object is instantiated is used as the time zone context for the DateTime properties of the calendar item that is created by using the ExchangeService object. The following code shows how to specify the Eastern Standard Time time zone when you instantiate the ExchangeService object.

    ExchangeService serviceEST = new ExchangeService(TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"));
    

    Or

    Set the StartTimeZone property and the EndTimeZone property on the calendar item. Setting these properties will specify the time zone for the start time, reminder due by time, and end time of the calendar item, regardless of the time zone on the ExchangeService that is used to create the item. In the following code example, Eastern Standard Time is specified for the appointment's StartTimeZone and EndTimeZone.

    appointment.StartTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
    appointment.EndTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
    

To specify a non-local time zone for a calendar item when you are using Exchange 2007 SP1

  • Specify the non-local time zone when you instantiate the ExchangeService object that will be used to create the calendar item, and do not set the StartTimeZone property on the calendar item. The time zone that is specified when the ExchangeService object is instantiated is used as the time zone context for the DateTime properties of the calendar item that is created by using the ExchangeService object. The following code shows how to specify the Eastern Standard Time time zone when you instantiate the ExchangeService object.

    ExchangeService serviceEST = new ExchangeService(TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"));
    

    Or

    Set the StartTimeZone property on the calendar item. Setting this property will specify the time zone for all DateTime properties on the calendar item, regardless of the time zone on the ExchangeService that is used to create the item. In the following code example, Eastern Standard Time is specified for the appointment's StartTimeZone.

    appointment.StartTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
    

To specify a non-local time zone for a non-calendar item

  • Specify the time zone when you instantiate the ExchangeService object that will be used to create the non-calendar item. For operations with non-calendar items, the time zone that is specified when the ExchangeService object is instantiated is the time zone context for all DateTime properties. The following code shows how to specify the Eastern Standard Time time zone when you instantiate the ExchangeService object.

    ExchangeService serviceEST = new ExchangeService(TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"));
    

Compiling the code

For information about compiling this code, see Getting started with the EWS Managed API 2.0.

Robust programming

  • Write appropriate error handling code for common search errors.

  • Review the client request XML that is sent to the Exchange server.

  • Review the server response XML that is sent from the Exchange server.

  • Set the service binding as shown in Setting the Exchange service URL by using the EWS Managed API 2.0. Do not hard code URLs because if mailboxes move, they might be serviced by a different Client Access server. If the client cannot connect to the service, retry setting the binding by using the AutodiscoverUrl(String) method.

  • Set the target Exchange Web Services schema version by setting the requestedServerVersion parameter of the ExchangeService constructor. For more information, see Versioning EWS requests by using the EWS Managed API 2.0.

Security

  • Use HTTP with SSL for all communication between client and server.

  • Always validate the server certificate that is used for establishing the SSL connections. For more information, see Validating X509 certificates by using the EWS Managed API 2.0.

  • Do not include user names and passwords in trace files.

  • Verify that Autodiscover lookups that use HTTP GET to find an endpoint always prompt for user confirmation; otherwise, they should be blocked.