Using Name Resolution (Exchange Web Services)

Topic Last Modified: 2007-09-17

You can use Exchange Web Services to resolve names against the Active Directory directory service and a user's contact folder.


The following example shows you how to resolve an ambiguous name. This example shows two possible resolutions for the given name.

static void Main()
    // Create the bindings and set the credentials.
    ExchangeServiceBinding esb = new ExchangeServiceBinding();
    esb.Url = "http://myExchangeServer/ews/exchange.asmx";

    esb.Credentials = new NetworkCredential("UserName", "Password", "Domain");

    // Create the ResolveNamesType and set the unresolved entry.
    ResolveNamesType rnType = new ResolveNamesType();
    rnType.ReturnFullContactData = true;
    rnType.UnresolvedEntry = "Test";

    // Resolve names.
    ResolveNamesResponseType resolveNamesResponse = esb.ResolveNames(rnType);

    // Check the result.
    if (resolveNamesResponse.ResponseMessages.Items.Length > 0 &&
        resolveNamesResponse.ResponseMessages.Items[0].ResponseClass != ResponseClassType.Error)
        ResolveNamesResponseMessageType responseMessage = resolveNamesResponse.ResponseMessages.Items[0] as ResolveNamesResponseMessageType;
        // Display the resolution information.
        foreach (ResolutionType resolutionType in responseMessage.ResolutionSet.Resolution)
            Console.WriteLine("EmailAddress: " + resolutionType.Mailbox.EmailAddress);
            Console.WriteLine("Name: " + resolutionType.Mailbox.Name);
            Console.WriteLine("MailboxType: " + resolutionType.Mailbox.MailboxType.ToString());
            Console.WriteLine("RoutingType: " + resolutionType.Mailbox.RoutingType);
            if (resolutionType.Mailbox.ItemId != null)
               Console.WriteLine("ItemId Id:" + resolutionType.Mailbox.ItemId.Id);
               Console.WriteLine("ItemId ChangeKey:" + resolutionType.Mailbox.ItemId.ChangeKey);

The following XML example shows the XML request message that is sent from the client to the server.

<?xml version="1.0" encoding="utf-8"?>
<ResolveNames xmlns:xsi="" 
      <UnresolvedEntry xmlns="">Test</UnresolvedEntry>

The following XML example shows the XML response message that is sent from the server to the client.

<?xml version="1.0" encoding="utf-8"?>
<ResolveNamesResponse xmlns:xsi="" 
  <ResponseMessages xmlns="">
    <ResolveNamesResponseMessage ResponseClass="Success">
      <ResolutionSet IncludesLastItemInRange="true" 
        <Resolution xmlns="">
              <Entry Key="EmailAddress1"></Entry>

The SOAP messages that are passed between the Exchange Web Services client and server are defined by the XML schema and WSDL files. The XML schema and WSDL files define the contract between the client and server. Proxy class generators create an object-model abstraction of those SOAP messages, which can simplify programming. This code example uses a proxy class library that was generated by Microsoft Visual Studio 2005. Different proxy class generators create different object models for a given Web service. This proxy class code example is an illustration only. Refer to the proxy class generator documentation for support for proxy classes.

Compiling the Code

For information about compiling the code, see Exchange Web Services Client Development.

Robust Programming

For information about robust programming, see Exchange Web Services Architecture.