Setting the Exchange service URL by using the EWS Managed API
Published: July 16, 2012
Learn how to set the Exchange service URL to use the EWS Managed API.
Applies to: Exchange 2013 | Exchange Online | Exchange Server 2007 Service Pack 1 (SP1) | Exchange Server 2010 | Exchange Web Services (EWS) Managed API
To use the Exchange Web Services (EWS) Managed API, you must set the Exchange service URL. You can provide the appropriate service binding manually, or by using the AutodiscoverUrl method. The AutodiscoverUrl method initializes the Url property to the Exchange Web Services URL for the specified email address by calling the Autodiscover service.
We recommend that you use the Autodiscover service because the Autodiscover service determines the best endpoint for a specific user. When you use the Autodiscover service, if the EWS URL changes, your code will not be affected.
To set the Exchange service binding manually
Set the EWS URL. Before you can do this, determine the EWS URL by using the Autodiscover service.
To set the Exchange service binding by using the Autodiscover service
The AutodiscoverUrl method uses the email address to set the ExchangeService endpoint and enables the mailbox user to perform any methods of the ExchangeService proxy classes.
Determine the server endpoints
After you obtain the URL for the Exchange server endpoints, you can communicate with the Exchange mailbox. The Exchange service Url property is similar to the following.
For information about compiling this code, see Getting started with the EWS Managed API.
Write appropriate error handling code for common search errors.
Review the client request XML sent to the Exchange server.
Review the server response XML sent from the Exchange server.
Set the service binding as shown in Setting the Exchange service URL by using the EWS Managed API. 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 method.
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.
Do not include user names and passwords in trace files.
Autodiscover lookups that use HTTP GET to find an endpoint should always prompt for user confirmation; otherwise, they should be blocked.
July 16, 2012