Set the EWS service URL by using the EWS Managed API

Find information about how to set the EWS service URL in your EWS Managed API application.

The service URL is the address that Exchange uses to communicate with Exchange Web Services (EWS). After your EWS Managed API application has this address, and has appropriate access to communicate with EWS, it can make calls to the ExchangeService class. The service URL for an on-premises Exchange server might look like the following.

https://computer.domain.contoso.com/EWS/Exchange.asmx

You can set the EWS URL in your application in a couple of ways. We recommend that you use the Autodiscover service to get the URL because in a large forest of servers, the URL can change if the mailbox is migrated to another server. However, because calling Autodiscover can take some time and can slow down your application if you need to make multiple calls in a short period of time, you might want to cache the URL value you get from Autodiscover and manually set the EWS service URL with this cached value. This will improve the performance of your application; just make sure that you use Autodiscover to update your cached value periodically in case the value changes on the server.

Set the EWS service URL by using the Autodiscover service

The AutodiscoverUrl method uses the email address to set the ExchangeService endpoint and enables your application to use any methods included in the ExchangeService proxy classes. The following example shows how to use the AutodiscoverURL method.

// Create the binding.
ExchangeService service = new ExchangeService();
// Set the credentials for the on-premises server.
service.Credentials = new WebCredentials("user1@contoso.com", "password");
// Set the URL.
service.AutodiscoverUrl("User1@contoso.com");

Set the Exchange service URL manually

The following example shows you how to set the EWS service URL by using a cached value. Before you do this, make sure to use the Autodiscover service to get the EWS URL.

// Create the binding.
ExchangeService service = new ExchangeService();
// Set the credentials for the on-premises server.
service.Credentials = new WebCredentials("user1@contoso.com", "password");
// Set the URL.
service.Url = new Uri("https://computername.domain.contoso.com/EWS/Exchange.asmx");

See also