Partager via


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.

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

Syntax

'Declaration
<GeneratedCodeAttribute("wsdl", "2.0.50727.42")> _
<WebServiceBindingAttribute(Name:="ExchangeServiceBinding", Namespace:="https://schemas.microsoft.com/exchange/services/2006/messages")> _
<XmlIncludeAttribute(GetType(AttendeeConflictData))> _
<XmlIncludeAttribute(GetType(BaseResponseMessageType))> _
<XmlIncludeAttribute(GetType(BaseSubscriptionRequestType))> _
<XmlIncludeAttribute(GetType(BaseGroupByType))> _
<XmlIncludeAttribute(GetType(RecurrenceRangeBaseType))> _
<DesignerCategoryAttribute("code")> _
<XmlIncludeAttribute(GetType(AttachmentType))> _
<XmlIncludeAttribute(GetType(ChangeDescriptionType))> _
<XmlIncludeAttribute(GetType(BasePagingType))> _
<XmlIncludeAttribute(GetType(BasePermissionType))> _
<XmlIncludeAttribute(GetType(BaseFolderType))> _
<XmlIncludeAttribute(GetType(BaseItemIdType))> _
<XmlIncludeAttribute(GetType(BaseEmailAddressType))> _
<XmlIncludeAttribute(GetType(BaseFolderIdType))> _
<XmlIncludeAttribute(GetType(BaseRequestType))> _
<XmlIncludeAttribute(GetType(RecurrencePatternBaseType))> _
<DebuggerStepThroughAttribute> _
Public Class ExchangeServiceBinding
    Inherits SoapHttpClientProtocol
[GeneratedCodeAttribute("wsdl", "2.0.50727.42")] 
[WebServiceBindingAttribute(Name="ExchangeServiceBinding", Namespace="https://schemas.microsoft.com/exchange/services/2006/messages")] 
[XmlIncludeAttribute(typeof(AttendeeConflictData))] 
[XmlIncludeAttribute(typeof(BaseResponseMessageType))] 
[XmlIncludeAttribute(typeof(BaseSubscriptionRequestType))] 
[XmlIncludeAttribute(typeof(BaseGroupByType))] 
[XmlIncludeAttribute(typeof(RecurrenceRangeBaseType))] 
[DesignerCategoryAttribute("code")] 
[XmlIncludeAttribute(typeof(AttachmentType))] 
[XmlIncludeAttribute(typeof(ChangeDescriptionType))] 
[XmlIncludeAttribute(typeof(BasePagingType))] 
[XmlIncludeAttribute(typeof(BasePermissionType))] 
[XmlIncludeAttribute(typeof(BaseFolderType))] 
[XmlIncludeAttribute(typeof(BaseItemIdType))] 
[XmlIncludeAttribute(typeof(BaseEmailAddressType))] 
[XmlIncludeAttribute(typeof(BaseFolderIdType))] 
[XmlIncludeAttribute(typeof(BaseRequestType))] 
[XmlIncludeAttribute(typeof(RecurrencePatternBaseType))] 
[DebuggerStepThroughAttribute] 
public class ExchangeServiceBinding : SoapHttpClientProtocol
[GeneratedCodeAttribute(L"wsdl", L"2.0.50727.42")] 
[WebServiceBindingAttribute(Name=L"ExchangeServiceBinding", Namespace=L"https://schemas.microsoft.com/exchange/services/2006/messages")] 
[XmlIncludeAttribute(typeof(AttendeeConflictData))] 
[XmlIncludeAttribute(typeof(BaseResponseMessageType))] 
[XmlIncludeAttribute(typeof(BaseSubscriptionRequestType))] 
[XmlIncludeAttribute(typeof(BaseGroupByType))] 
[XmlIncludeAttribute(typeof(RecurrenceRangeBaseType))] 
[DesignerCategoryAttribute(L"code")] 
[XmlIncludeAttribute(typeof(AttachmentType))] 
[XmlIncludeAttribute(typeof(ChangeDescriptionType))] 
[XmlIncludeAttribute(typeof(BasePagingType))] 
[XmlIncludeAttribute(typeof(BasePermissionType))] 
[XmlIncludeAttribute(typeof(BaseFolderType))] 
[XmlIncludeAttribute(typeof(BaseItemIdType))] 
[XmlIncludeAttribute(typeof(BaseEmailAddressType))] 
[XmlIncludeAttribute(typeof(BaseFolderIdType))] 
[XmlIncludeAttribute(typeof(BaseRequestType))] 
[XmlIncludeAttribute(typeof(RecurrencePatternBaseType))] 
[DebuggerStepThroughAttribute] 
public ref class ExchangeServiceBinding : public SoapHttpClientProtocol
/** @attribute GeneratedCodeAttribute("wsdl", "2.0.50727.42") */ 
/** @attribute WebServiceBindingAttribute(Name="ExchangeServiceBinding", Namespace="https://schemas.microsoft.com/exchange/services/2006/messages") */ 
/** @attribute XmlIncludeAttribute(ExchangeWebServices.AttendeeConflictData) */ 
/** @attribute XmlIncludeAttribute(ExchangeWebServices.BaseResponseMessageType) */ 
/** @attribute XmlIncludeAttribute(ExchangeWebServices.BaseSubscriptionRequestType) */ 
/** @attribute XmlIncludeAttribute(ExchangeWebServices.BaseGroupByType) */ 
/** @attribute XmlIncludeAttribute(ExchangeWebServices.RecurrenceRangeBaseType) */ 
/** @attribute DesignerCategoryAttribute("code") */ 
/** @attribute XmlIncludeAttribute(ExchangeWebServices.AttachmentType) */ 
/** @attribute XmlIncludeAttribute(ExchangeWebServices.ChangeDescriptionType) */ 
/** @attribute XmlIncludeAttribute(ExchangeWebServices.BasePagingType) */ 
/** @attribute XmlIncludeAttribute(ExchangeWebServices.BasePermissionType) */ 
/** @attribute XmlIncludeAttribute(ExchangeWebServices.BaseFolderType) */ 
/** @attribute XmlIncludeAttribute(ExchangeWebServices.BaseItemIdType) */ 
/** @attribute XmlIncludeAttribute(ExchangeWebServices.BaseEmailAddressType) */ 
/** @attribute XmlIncludeAttribute(ExchangeWebServices.BaseFolderIdType) */ 
/** @attribute XmlIncludeAttribute(ExchangeWebServices.BaseRequestType) */ 
/** @attribute XmlIncludeAttribute(ExchangeWebServices.RecurrencePatternBaseType) */ 
/** @attribute DebuggerStepThroughAttribute() */ 
public class ExchangeServiceBinding extends SoapHttpClientProtocol
GeneratedCodeAttribute("wsdl", "2.0.50727.42") 
WebServiceBindingAttribute(Name="ExchangeServiceBinding", Namespace="https://schemas.microsoft.com/exchange/services/2006/messages") 
XmlIncludeAttribute(ExchangeWebServices.AttendeeConflictData) 
XmlIncludeAttribute(ExchangeWebServices.BaseResponseMessageType) 
XmlIncludeAttribute(ExchangeWebServices.BaseSubscriptionRequestType) 
XmlIncludeAttribute(ExchangeWebServices.BaseGroupByType) 
XmlIncludeAttribute(ExchangeWebServices.RecurrenceRangeBaseType) 
DesignerCategoryAttribute("code") 
XmlIncludeAttribute(ExchangeWebServices.AttachmentType) 
XmlIncludeAttribute(ExchangeWebServices.ChangeDescriptionType) 
XmlIncludeAttribute(ExchangeWebServices.BasePagingType) 
XmlIncludeAttribute(ExchangeWebServices.BasePermissionType) 
XmlIncludeAttribute(ExchangeWebServices.BaseFolderType) 
XmlIncludeAttribute(ExchangeWebServices.BaseItemIdType) 
XmlIncludeAttribute(ExchangeWebServices.BaseEmailAddressType) 
XmlIncludeAttribute(ExchangeWebServices.BaseFolderIdType) 
XmlIncludeAttribute(ExchangeWebServices.BaseRequestType) 
XmlIncludeAttribute(ExchangeWebServices.RecurrencePatternBaseType) 
DebuggerStepThroughAttribute 
public class ExchangeServiceBinding extends 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.

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

Example

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.

Platforms

Development Platforms

Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003,

Target Platforms

Windows 98, Windows 2000, Windows 2000 Server, Windows CE, Windows Longhorn, Windows 98 Second Edition, Pocket PC, Smart Phone, Windows Server 2003, Windows XP Professional with Service Pack 2 (SP2)