Resolving ambiguous names by using the EWS Managed API 2.0
You can use the Microsoft Exchange Web Services (EWS) Managed API to resolve ambiguous names against Active Directory and Microsoft Exchange mailbox contacts.
Last modified: October 13, 2012
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.
Example
The following example shows how to resolve a name against both Active Directory and mailbox contacts.
static void ResolveNames(ExchangeService service)
{
// Identify the mailbox folders to search for potential name resolution matches.
List<FolderId> folders = new List<FolderId>() { new FolderId(WellKnownFolderName.Contacts)};
// Search for all contact entries in the default mailbox contacts folder and in Active Directory Domain Services (AD DS). This results in a call to EWS.
NameResolutionCollection coll = service.ResolveName("Johnson", folders, ResolveNameSearchLocation.ContactsThenDirectory, false);
foreach (NameResolution nameRes in coll)
{
Console.WriteLine("Contact name: " + nameRes.Mailbox.Name);
Console.WriteLine("Contact e-mail address: " + nameRes.Mailbox.Address);
Console.WriteLine("Mailbox type: " + nameRes.Mailbox.MailboxType);
}
}
Sub ResolveNames(ByVal service As ExchangeService)
' Identify the mailbox folders to search for potential name resolution matches.
Dim folders As New List(Of FolderId)
folders.Add(New FolderId(WellKnownFolderName.Contacts))
' Search for all contact entries in the default mailbox contacts folder and in Active Directory.
' This results in a call to EWS.
Dim resolutions As NameResolutionCollection = service.ResolveName("Johnson", _
folders, _
ResolveNameSearchLocation.ContactsThenDirectory, _
True)
Dim resolution As NameResolution
For Each resolution In resolutions
Console.WriteLine(("Contact name: " & resolution.Mailbox.Name))
Console.WriteLine(("Contact e-mail address: " & resolution.Mailbox.Address))
Console.WriteLine(("Mailbox type: " & resolution.Mailbox.MailboxType))
Next
End Sub
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.