Partager via


Expanding Distribution Lists in Exchange 2010

Last modified: May 21, 2009

Applies to: Exchange Server 2007 | Exchange Server 2010

You can use Exchange Web Services to expand the membership of a single public or private distribution list.

Example

The following example shows you how to display the membership of a distribution list.

static void ExpandDL(ExchangeServiceBinding esb)
{
    // Create an ExpandDLType.
    ExpandDLType expandDl = new ExpandDLType();

    // Set the e-mail address and routing type of the distribution list.
    expandDl.Mailbox = new EmailAddressType();
    expandDl.Mailbox.EmailAddress = "myDL@myDomain.com";

    // Expand the distribution list.
    ExpandDLResponseType expandDlResponse = esb.ExpandDL(expandDl);

    // Check the result.
    if (expandDlResponse.ResponseMessages.Items.Length > 0 &&
        expandDlResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Success)
    {
        ExpandDLResponseMessageType dlResponse = expandDlResponse.ResponseMessages.Items[0] as ExpandDLResponseMessageType;

        // Get the distribution list expansion list.
        ArrayOfDLExpansionType expansionList = dlResponse.DLExpansion;

        // Display the distribution list members.
        foreach (EmailAddressType address in expansionList.Mailbox)
        {
            Console.WriteLine("Email Address: {0}", address.EmailAddress);
        }
    }

    /*********************************************
            EXPANDDL REQUEST XML

     
_********************************************_
            EXPANDDL RESPONSE XML
      
      
    **********************************************/
}

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"?>
<ExpandDL xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
              xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Mailbox xmlns="https://schemas.microsoft.com/exchange/services/2006/messages">
    <EmailAddress xmlns="https://schemas.microsoft.com/exchange/services/2006/types">myDL@myDomain.com</EmailAddress>
  </Mailbox>
</ExpandDL>

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"?>
<ExpandDLResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                      xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <ResponseMessages xmlns="https://schemas.microsoft.com/exchange/services/2006/messages">
    <ExpandDLResponseMessage ResponseClass="Success">
      <ResponseCode>NoError</ResponseCode>
      <DLExpansion IncludesLastItemInRange="true" TotalItemsInView="4">
        <Mailbox xmlns="https://schemas.microsoft.com/exchange/services/2006/types">
          <Name>User1</Name>
          <EmailAddress>user1@myDomain.com</EmailAddress>
          <RoutingType>SMTP</RoutingType>
          <MailboxType>Mailbox</MailboxType>
        </Mailbox>
        <Mailbox xmlns="https://schemas.microsoft.com/exchange/services/2006/types">
          <Name>User2</Name>
          <EmailAddress>user2@myDomain.com</EmailAddress>
          <RoutingType>SMTP</RoutingType>
          <MailboxType>Mailbox</MailboxType>
        </Mailbox>
        <Mailbox xmlns="https://schemas.microsoft.com/exchange/services/2006/types">
          <Name>User3</Name>
          <EmailAddress>user3@myDomain.com</EmailAddress>
          <RoutingType>SMTP</RoutingType>
          <MailboxType>Mailbox</MailboxType>
        </Mailbox>
        <Mailbox xmlns="https://schemas.microsoft.com/exchange/services/2006/types">
          <Name>User4</Name>
          <EmailAddress>user4@myDomain.com</EmailAddress>
          <RoutingType>SMTP</RoutingType>
          <MailboxType>Mailbox</MailboxType>
        </Mailbox>
      </DLExpansion>
    </ExpandDLResponseMessage>
  </ResponseMessages>
</ExpandDLResponse>

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 MicrosoftVisual 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.

Note

The item identifier and change key have been shortened to preserve readability.

Compiling the Code

For information about compiling the code, see EWS Client Development in Exchange 2010.

Robust Programming

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

See Also

Other Resources