Export (0) Print
Expand All

ClientBase<TChannel> Class

Provides the base implementation used to create Windows Communication Foundation (WCF) client objects that can call services.

Namespace:  System.ServiceModel
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

public abstract class ClientBase<TChannel> : ICommunicationObject, 
	IDisposable 
where TChannel : class

Type Parameters

TChannel

The channel to be used to connect to the service.

The ClientBase<TChannel> type exposes the following members.

  NameDescription
Protected methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsClientBase<TChannel>()Initializes a new instance of the ClientBase<TChannel> class using the default target endpoint from the application configuration file.
Protected methodClientBase<TChannel>(InstanceContext)Initializes a new instance of the ClientBase<TChannel> class using the callbackInstance as the callback object in a duplex conversation.
Protected methodClientBase<TChannel>(ServiceEndpoint)Initializes a new instance of the ClientBase<TChannel> class using the specified System.ServiceModel.Description.ServiceEndpoint.
Protected methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsClientBase<TChannel>(String)Initializes a new instance of the ClientBase<TChannel> class using the configuration information specified in the application configuration file by endpointConfigurationName.
Protected methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsClientBase<TChannel>(Binding, EndpointAddress)Initializes a new instance of the ClientBase<TChannel> class using the specified binding and target address.
Protected methodClientBase<TChannel>(InstanceContext, ServiceEndpoint)Initializes a new instance of the ClientBase<TChannel> class using the specified InstanceContext and System.ServiceModel.Description.ServiceEndpoint objects.
Protected methodClientBase<TChannel>(InstanceContext, String)Initializes a new instance of the ClientBase<TChannel> class using the specified callback service and endpoint configuration information.
Protected methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsClientBase<TChannel>(String, EndpointAddress)Initializes a new instance of the ClientBase<TChannel> class using the specified target address and endpoint information.
Protected methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsClientBase<TChannel>(String, String)Initializes a new instance of the ClientBase<TChannel> class.
Protected methodClientBase<TChannel>(InstanceContext, Binding, EndpointAddress)Initializes a new instance of the ClientBase<TChannel> class.
Protected methodClientBase<TChannel>(InstanceContext, String, EndpointAddress)Initializes a new instance of the ClientBase<TChannel> class.
Protected methodClientBase<TChannel>(InstanceContext, String, String)Initializes a new instance of the ClientBase<TChannel> class.
Top

  NameDescription
Public propertyStatic memberCacheSettingGets or sets the cache setting.
Protected propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsChannelGets the inner channel used to send messages to variously configured service endpoints.
Public propertySupported in .NET for Windows Store appsChannelFactoryGets the underlying ChannelFactory<TChannel> object.
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsClientCredentialsGets the client credentials used to call an operation.
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsEndpointGets the target endpoint for the service to which the WCF client can connect.
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsInnerChannelGets the underlying IClientChannel implementation.
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsStateGets the current state of the ClientBase<TChannel> object.
Top

  NameDescription
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsAbortCauses the ClientBase<TChannel> object to transition immediately from its current state into the closed state.
Public methodCloseCauses the ClientBase<TChannel> object to transition from its current state into the closed state.
Protected methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsCreateChannelReturns a new channel to the service.
Public methodDisplayInitializationUIInstructs the inner channel to display a user interface if one is required to initialize the channel prior to using it.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Protected methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetDefaultValueForInitialization<T>Replicates the behavior of the default keyword in C#.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsInvokeAsyncProvides support for implementing the event-based asynchronous pattern. For more information about this pattern, see Event-based Asynchronous Pattern Overview.
Protected methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodOpenCauses the ClientBase<TChannel> object to transition from the created state into the opened state.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Explicit interface implemetationPrivate methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsICommunicationObject.BeginClose(AsyncCallback, Object)Begins an asynchronous operation to close the ClientBase<TChannel>.
Explicit interface implemetationPrivate methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsICommunicationObject.BeginClose(TimeSpan, AsyncCallback, Object)Begins an asynchronous operation to close the ClientBase<TChannel> with a specified timeout.
Explicit interface implemetationPrivate methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsICommunicationObject.BeginOpen(AsyncCallback, Object)Begins an asynchronous operation to open the ClientBase<TChannel> object.
Explicit interface implemetationPrivate methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsICommunicationObject.BeginOpen(TimeSpan, AsyncCallback, Object)Begins an asynchronous operation to open the ClientBase<TChannel> object within a specified interval of time.
Explicit interface implemetationPrivate methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsICommunicationObject.Close()
Explicit interface implemetationPrivate methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsICommunicationObject.Close(TimeSpan)Causes the ClientBase<TChannel> object to transition from its current state into the closed state.
Explicit interface implemetationPrivate eventSupported by Portable Class LibrarySupported in .NET for Windows Store appsICommunicationObject.ClosedThe event handler that is invoked when the ClientBase<TChannel> object has transitioned from its current state to the closed state.
Explicit interface implemetationPrivate eventSupported by Portable Class LibrarySupported in .NET for Windows Store appsICommunicationObject.ClosingThe event handler that is invoked when the ClientBase<TChannel> object transitions from its current state to the closed state.
Explicit interface implemetationPrivate methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsICommunicationObject.EndCloseCompletes an asynchronous operation to close the ClientBase<TChannel> object.
Explicit interface implemetationPrivate methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsICommunicationObject.EndOpenCompletes an asynchronous operation to open the ClientBase<TChannel> object.
Explicit interface implemetationPrivate eventSupported by Portable Class LibrarySupported in .NET for Windows Store appsICommunicationObject.FaultedThe event handler that is invoked when a fault occurs while performing an operation on the ClientBase<TChannel> object.
Explicit interface implemetationPrivate methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsICommunicationObject.Open()
Explicit interface implemetationPrivate methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsICommunicationObject.Open(TimeSpan)Causes the ClientBase<TChannel> object to transition from the created state into the opened state within a specified interval of time.
Explicit interface implemetationPrivate eventSupported by Portable Class LibrarySupported in .NET for Windows Store appsICommunicationObject.OpenedThe event handler that is invoked when the ClientBase<TChannel> object transitions from the created state to the opened state.
Explicit interface implemetationPrivate eventSupported by Portable Class LibrarySupported in .NET for Windows Store appsICommunicationObject.OpeningThe event handler that is invoked when the ClientBase<TChannel> object transitions from the created state to the opened state.
Explicit interface implemetationPrivate methodIDisposable.DisposeExplicit implementation of the Dispose method.
Top

Extend the ClientBase<TChannel> class to create a custom WCF client object that can be used to connect to a service. Typically, the WCF client base class is extended by a tool such as the ServiceModel Metadata Utility Tool (Svcutil.exe) on your behalf. For an example, see the Example section.

The ClientBase<TChannel> class can be used quickly and easily by developers who prefer objects to the use of the interfaces and the System.ServiceModel.ChannelFactory<TChannel> class. In all cases this class wraps or exposes the methods and functionality of the System.ServiceModel.ChannelFactory<TChannel> class and the System.ServiceModel.IClientChannel interface.

As when using the System.ServiceModel.ServiceHost class, you can create the class and modify the endpoint, channel factory, or security information prior to making any calls or calling Open. For more information, see WCF Client Overview and Accessing Services Using a WCF Client.

Special note for Managed C++ users deriving from this class:

  • Put your clean-up code in (On)(Begin)Close (and/or OnAbort), not in a destructor.

  • Avoid destructors: they cause the compiler to auto-generate IDisposable.

  • Avoid non-reference members: they can cause the compiler to auto-generate IDisposable.

  • Avoid finalizers; but if you include one, you should suppress the build warning and call SuppressFinalize(Object) and the finalizer itself from (On)(Begin)Close (and/or OnAbort) to emulate what would have been the auto-generated IDisposable behavior.

The following code example shows how the ServiceModel Metadata Utility Tool (Svcutil.exe) extends the ClientBase<TChannel> class to create a WCF client class.

public partial class SampleServiceClient : System.ServiceModel.ClientBase<ISampleService>, ISampleService
{

    public SampleServiceClient()
    {
    }

    public SampleServiceClient(string endpointConfigurationName) : 
            base(endpointConfigurationName)
    {
    }

    public SampleServiceClient(string endpointConfigurationName, string remoteAddress) : 
            base(endpointConfigurationName, remoteAddress)
    {
    }

    public SampleServiceClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
            base(endpointConfigurationName, remoteAddress)
    {
    }

    public SampleServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
            base(binding, remoteAddress)
    {
    }

    public string SampleMethod(string msg)
    {
        return base.Channel.SampleMethod(msg);
    }
}

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft