Jaa


ExchangeServiceBinding Class

The ExchangeServiceBinding class contains the methods and properties that are used to send and receive the SOAP messages, set up Exchange impersonation, maintain user credentials, and identify the Exchange Web Services endpoint.

Inheritance Hierarchy

System.Object
  System.MarshalByRefObject
    System.ComponentModel.Component
      System.Web.Services.Protocols.WebClientProtocol
        System.Web.Services.Protocols.HttpWebClientProtocol
          System.Web.Services.Protocols.SoapHttpClientProtocol
            ExchangeWebServices.ExchangeServiceBinding

Namespace:  ExchangeWebServices
Assembly:  EWS (in EWS.dll)

Syntax

'Declaration
<WebServiceBindingAttribute(Name := "ExchangeServiceBinding", Namespace := "https://schemas.microsoft.com/exchange/services/2006/messages")> _
Public Class ExchangeServiceBinding _
    Inherits SoapHttpClientProtocol
'Usage
Dim instance As ExchangeServiceBinding
[WebServiceBindingAttribute(Name = "ExchangeServiceBinding", Namespace = "https://schemas.microsoft.com/exchange/services/2006/messages")]
public class ExchangeServiceBinding : SoapHttpClientProtocol

Remarks

The ExchangeServiceBinding class also contains methods for synchronous and asynchronous calls to the Exchange server. The ExchangeServiceBinding class that is described in this topic was created by using wsdl.exe version 2.0.50727.42. The ExchangeServiceBinding class that is created by using the Add Web Reference option from the Solutions Explorer pane of Microsoft Visual Studio 2005 is different. It contains a property named UseDefaultCredentials. If UseDefaultCredentials is set to true, the default credentials of the current user are used to make the Web service call. To use default credentials in a proxy that was created by using wsdl.exe, use the System.Net.CredentialCache static class to get the default system credentials and apply the credentials to the Credentials property of the ExchangeServiceBinding class. There are additional asynchronous methods for calling the Exchange Web Services on the ExchangeServiceBinding class that is created by using wsdl.exe. To view the differences, use a diff tool on the proxy files that were created by using wsdl.exe and the Add Web Reference option in Visual Studio 2005.

For an example of an asynchronous Web service call, see FindFolderAsync.

Examples

The following code example shows how to set up the ExchangeServiceBinding class with credentials, the URL of the service, and Exchange impersonation. This example shows USER1 performing a FindItem call on the Inbox of USER2. USER1 is impersonating USER2.

Note

This example will run without the three lines that perform the Exchange impersonation. If these three lines are commented out, the example will search the Inbox of USER1. If these three lines remain in this example, Exchange impersonation must be configured for USER1.

static void FindExample()
{
    // Set up the binding with credentials and URL.
    ExchangeServiceBinding binding = new ExchangeServiceBinding();
    binding.Credentials = new NetworkCredential("USER1", "password", "exampledomain.com");
    binding.Url = @"https://ExchangeServer.exampledomain.com/EWS/Exchange.asmx";

    // Set up the binding for Exchange impersonation.
    binding.ExchangeImpersonation = new ExchangeImpersonationType();
    binding.ExchangeImpersonation.ConnectingSID = new ConnectingSIDType();
    binding.ExchangeImpersonation.ConnectingSID.PrimarySmtpAddress = "USER2@exampledomain.com";

    // Create the request.
    FindItemType request = new FindItemType();
    request.ItemShape = new ItemResponseShapeType();
    request.ItemShape.BaseShape = DefaultShapeNamesType.Default;
    request.Traversal = ItemQueryTraversalType.Shallow;
    request.ParentFolderIds = new BaseFolderIdType[1];
    DistinguishedFolderIdType inbox = new DistinguishedFolderIdType();
    inbox.Id = DistinguishedFolderIdNameType.inbox;
    request.ParentFolderIds[0] = inbox;

    // Send the request and get the response by using the binding object.
    FindItemResponseType response = binding.FindItem(request);
}

Note

The Exchange server will return a 405 error if \ews or \ews\ is used for the endpoint instead of the full path of Exchange.asmx. By default, Internet Information Services (IIS) does not redirect requests to \ews and \ews\ to the appropriate Exchange.asmx endpoint.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.