Partager via


Setting Up the ExchangeServiceBinding Proxy Class in Exchange 2010

Last modified: October 14, 2009

Applies to: Exchange Server 2007 | Exchange Server 2010

In this article
Setting Credentials
Setting the Request Version
Setting the URL Endpoint
Identifying the Operation That Will Process the Request
ExchangeServiceBinding Configuration Example
Next Step

The ExchangeServiceBinding proxy class contains the methods and properties that are used to send and receive the SOAP messages, set up Exchange impersonation, maintain user credentials, specify the version of the schema files that should be used to validate and process client requests, and identify the Exchange Web Services (EWS) endpoint. When you are creating Exchange Web Services proxies, you must set up the ExchangeServiceBinding proxy class. This involves the following tasks:

  1. Setting the credentials of the user who is sending and receiving the XML requests and responses.

  2. Specifying the version of the schema files that should be used to validate and process client requests.

  3. Setting the URL endpoint from which the Exchange service binding receives requests and sends responses.

  4. Identifying the operation that will process the requests.

Note

The ExchangeServiceBinding class is created by Microsoft Visual Studio 2005 or Microsoft Visual Studio 2008 when you create a Web reference from the EWS WSDL file in Microsoft Exchange Server 2010.

Setting Credentials

Set the credentials of the user who sends requests to the Exchange server. If you use the Add Web Reference user interface in Visual Studio 2005 or Visual Studio 2008 to create the proxy classes, you can use the default credentials of the authenticated user who is logged on to the application. To use the default user credentials, set the UseDefaultCredentials property on the ExchangeServiceBinding to true. If you are not using the default user credentials, use the Credentials property of the ExchangeServiceBinding class to explicitly set the credentials to a different user.

Note

The UseDefaultCredentials property is not created for the ExchangeServiceBinding proxy class if you use wsdl.exe to generate the proxy classes. Use CredentialCache.DefaultCredentials to set the ExchangeServiceBinding to use the default user credentials.

Setting the Request Version

Specify the version of schema files that should be used to validate and process client requests by setting the RequestServerVersionValue property of the ExchangeServiceBinding class. For more information about setting the request version, see Versioning EWS Requests in Exchange 2010.

Setting the URL Endpoint

Set the URL of the Exchange Web Services endpoint on the URL property of the ExchangeServiceBinding class. This URL locates the exchange.asmx file on the Exchange server that is running the Client Access server role.

Note

You can use the Autodiscover service to query for the appropriate URL endpoint for the mailbox user if the URL is unknown. The URL that is returned in the ASUrl element in an Autodiscover response identifies the Exchange Web Services endpoint. For an example of how to use the Autodiscover service, see Autodiscover Sample Application.

Identifying the Operation That Will Process the Request

The ExchangeServiceBinding class contains a set of methods that correspond to the Web service methods that are implemented on the Exchange server. Each of these methods takes a particular corresponding type as an argument. The type that is provided as an argument has properties set on it that are serialized by the ExchangeServiceBinding into the XML payload that is sent to the Client Access server. For a list of operations that can be performed with the Web service methods that are provided by the ExchangeServiceBinding class, see Exchange Web Services Operations.

ExchangeServiceBinding Configuration Example

The following code example shows how to set up the ExchangeServiceBinding class to enable communication with the Exchange 2010 Client Access server that hosts Exchange Web Services.

01    ExchangeServiceBinding esb = new ExchangeServiceBinding();
02    esb.RequestServerVersionValue = new RequestServerVersion();
03    esb.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2010;
04    esb.Credentials = new NetworkCredential("username", "password", "domain");
05    esb.Url = "https://CAS01.contoso.com/EWS/exchange.asmx";

This code example does the following:

  • Line 01 declares and instantiates an instance of the ExchangeServiceBinding class.

    Important

    Use a single instance of the ExchangeServiceBinding class for each mailbox account that is accessed from an Exchange Web Services client application. The exception to this is when you use multiple threads to access the same mailbox. Then use multiple instances of the ExchangeServiceBinding for the multiple threads.

  • Line 02 initializes the RequestServerVersionValue property of the ExchangeServiceBinding class.

  • Line 03 specifies Exchange Server 2010 as the version of schema files that the requests will target.

  • Line 04 sets the credentials of the user who sends requests to the Exchange server.

  • Line 05 sets the URL endpoint of Exchange Web Services. CAS01.contoso.com represents the fully qualified domain name (FQDN) of the Client Access server that provides client access for the mailbox user identified in Line 04.

Next Step

After you set up the ExchangeServiceBinding proxy class, you must handle X509 certificates for SSL over HTTP.