Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ClientBase Generic 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
J# supports the use of generic types and methods, but not the declaration of new ones.
JScript does not support generic types and methods.
Not applicable.

Type Parameters


The channel to be used to connect to the service.

Extend the ClientBase 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 class can be used quickly and easily by developers who prefer objects to the use of the interfaces and the System.ServiceModel.ChannelFactory class. In all cases this class wraps or exposes the methods and functionality of the System.ServiceModel.ChannelFactory 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 Consuming Services Using a WCF Client.

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

  • Put your cleanup 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 and the finalizer itself from (On)(Begin)Close (and/or OnAbort) in order 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 class to create a WCF client class.

public partial class SampleServiceClient : System.ServiceModel.ClientBase<ISampleService>, ISampleService
    public SampleServiceClient()
    public SampleServiceClient(string 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);

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

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

© 2017 Microsoft