Export (0) Print
Expand All

DuplexClientBase<TChannel> Class

Used to create a channel to a duplex service and associate that channel with a callback object.

System.Object
  System.ServiceModel.ClientBase<TChannel>
    System.ServiceModel.DuplexClientBase<TChannel>

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

public abstract class DuplexClientBase<TChannel> : ClientBase<TChannel>
where TChannel : class

Type Parameters

TChannel

The type of the channel to be created.

The DuplexClientBase<TChannel> type exposes the following members.

  NameDescription
Protected methodSupported in .NET for Windows Store appsDuplexClientBase<TChannel>(InstanceContext)Initializes a new instance of the DuplexClientBase<TChannel> class using the specified callback object.
Protected methodDuplexClientBase<TChannel>(Object)Initializes a new instance of the DuplexClientBase<TChannel> class using the specified callback object.
Protected methodDuplexClientBase<TChannel>(InstanceContext, ServiceEndpoint)Initializes a new instance of the DuplexClientBase<TChannel> class with the specified callback object and service endpoint.
Protected methodSupported in .NET for Windows Store appsDuplexClientBase<TChannel>(InstanceContext, String)Initializes a new instance of the DuplexClientBase<TChannel> class using the specified callback object and configuration name.
Protected methodDuplexClientBase<TChannel>(Object, ServiceEndpoint)Initializes a new instance of the DuplexClientBase<TChannel> class with the specified callback object and service endpoint.
Protected methodDuplexClientBase<TChannel>(Object, String)Initializes a new instance of the DuplexClientBase<TChannel> class using the specified callback object and configuration name.
Protected methodSupported in .NET for Windows Store appsDuplexClientBase<TChannel>(InstanceContext, Binding, EndpointAddress)Initializes a new instance of the DuplexClientBase<TChannel> class using the specified callback object, binding, and service endpoint address.
Protected methodSupported in .NET for Windows Store appsDuplexClientBase<TChannel>(InstanceContext, String, EndpointAddress)Initializes a new instance of the DuplexClientBase<TChannel> class using the specified callback object, configuration name, and service endpoint address.
Protected methodSupported in .NET for Windows Store appsDuplexClientBase<TChannel>(InstanceContext, String, String)Initializes a new instance of the DuplexClientBase<TChannel> class using the specified callback object, configuration name, and service endpoint address.
Protected methodDuplexClientBase<TChannel>(Object, Binding, EndpointAddress)Initializes a new instance of the DuplexClientBase<TChannel> class using the specified callback object, binding, and service endpoint address.
Protected methodDuplexClientBase<TChannel>(Object, String, EndpointAddress)Initializes a new instance of the DuplexClientBase<TChannel> class using the specified callback object, configuration name, and service endpoint address.
Protected methodDuplexClientBase<TChannel>(Object, String, String)Initializes a new instance of the DuplexClientBase<TChannel> class using the specified callback object, endpoint configuration name, and service endpoint address.
Top

  NameDescription
Protected propertySupported in .NET for Windows Store appsChannelGets the inner channel used to send messages to variously configured service endpoints. (Inherited from ClientBase<TChannel>.)
Public propertySupported in .NET for Windows Store appsChannelFactoryGets the underlying ChannelFactory<TChannel> object. (Inherited from ClientBase<TChannel>.)
Public propertySupported in .NET for Windows Store appsClientCredentialsGets the client credentials used to call an operation. (Inherited from ClientBase<TChannel>.)
Public propertySupported in .NET for Windows Store appsEndpointGets the target endpoint for the service to which the WCF client can connect. (Inherited from ClientBase<TChannel>.)
Public propertySupported in .NET for Windows Store appsInnerChannelGets the underlying IClientChannel implementation. (Inherited from ClientBase<TChannel>.)
Public propertyInnerDuplexChannelGets the inner duplex channel.
Public propertySupported in .NET for Windows Store appsStateGets the current state of the ClientBase<TChannel> object. (Inherited from ClientBase<TChannel>.)
Top

  NameDescription
Public methodSupported in .NET for Windows Store appsAbortCauses the ClientBase<TChannel> object to transition immediately from its current state into the closed state. (Inherited from ClientBase<TChannel>.)
Public methodCloseCauses the ClientBase<TChannel> object to transition from its current state into the closed state. (Inherited from ClientBase<TChannel>.)
Protected methodCreateChannelReturns a new channel to the service. (Inherited from ClientBase<TChannel>.)

In .NET Framework Client Profile, this member is overridden by CreateChannel().
Public methodDisplayInitializationUIInstructs the inner channel to display a user interface if one is required to initialize the channel prior to using it. (Inherited from ClientBase<TChannel>.)
Public methodSupported in .NET for Windows Store appsEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodSupported 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 in .NET for Windows Store appsGetDefaultValueForInitialization<T>Replicates the behavior of the default keyword in C#. (Inherited from ClientBase<TChannel>.)
Public methodSupported in .NET for Windows Store appsGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodSupported in .NET for Windows Store appsGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodSupported 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. (Inherited from ClientBase<TChannel>.)
Protected methodSupported 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. (Inherited from ClientBase<TChannel>.)
Public methodSupported in .NET for Windows Store appsToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Explicit interface implemetationPrivate methodSupported in .NET for Windows Store appsICommunicationObject.BeginClose(AsyncCallback, Object)Begins an asynchronous operation to close the ClientBase<TChannel>. (Inherited from ClientBase<TChannel>.)
Explicit interface implemetationPrivate methodSupported in .NET for Windows Store appsICommunicationObject.BeginClose(TimeSpan, AsyncCallback, Object)Begins an asynchronous operation to close the ClientBase<TChannel> with a specified timeout. (Inherited from ClientBase<TChannel>.)
Explicit interface implemetationPrivate methodSupported in .NET for Windows Store appsICommunicationObject.BeginOpen(AsyncCallback, Object)Begins an asynchronous operation to open the ClientBase<TChannel> object. (Inherited from ClientBase<TChannel>.)
Explicit interface implemetationPrivate methodSupported 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. (Inherited from ClientBase<TChannel>.)
Explicit interface implemetationPrivate methodSupported in .NET for Windows Store appsICommunicationObject.Close() (Inherited from ClientBase<TChannel>.)
Explicit interface implemetationPrivate methodSupported in .NET for Windows Store appsICommunicationObject.Close(TimeSpan)Causes the ClientBase<TChannel> object to transition from its current state into the closed state. (Inherited from ClientBase<TChannel>.)
Explicit interface implemetationPrivate eventSupported 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. (Inherited from ClientBase<TChannel>.)
Explicit interface implemetationPrivate eventSupported 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. (Inherited from ClientBase<TChannel>.)
Explicit interface implemetationPrivate methodSupported in .NET for Windows Store appsICommunicationObject.EndCloseCompletes an asynchronous operation to close the ClientBase<TChannel> object. (Inherited from ClientBase<TChannel>.)
Explicit interface implemetationPrivate methodSupported in .NET for Windows Store appsICommunicationObject.EndOpenCompletes an asynchronous operation to open the ClientBase<TChannel> object. (Inherited from ClientBase<TChannel>.)
Explicit interface implemetationPrivate eventSupported 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. (Inherited from ClientBase<TChannel>.)
Explicit interface implemetationPrivate methodSupported in .NET for Windows Store appsICommunicationObject.Open() (Inherited from ClientBase<TChannel>.)
Explicit interface implemetationPrivate methodSupported 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. (Inherited from ClientBase<TChannel>.)
Explicit interface implemetationPrivate eventSupported 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. (Inherited from ClientBase<TChannel>.)
Explicit interface implemetationPrivate eventSupported 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. (Inherited from ClientBase<TChannel>.)
Explicit interface implemetationPrivate methodIDisposable.DisposeExplicit implementation of the Dispose method. (Inherited from ClientBase<TChannel>.)
Top

Use the DuplexClientBase<TChannel> class to create a channel to a service that specifies a callback object. The DuplexClientBase<TChannel> object wraps a System.ServiceModel.DuplexChannelFactory<TChannel> object, which provides the connectivity for the WCF object. You can use either type to connect to a duplex service. For more information about duplex services, see Duplex Services.

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(Object) 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 example shows the use in the client of a duplex WCF client type, the SampleDuplexHelloClient, to pass a new System.ServiceModel.InstanceContext object with the callback object to listen for callbacks.

using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Threading;

namespace Microsoft.WCF.Documentation
{
  [CallbackBehaviorAttribute(
   IncludeExceptionDetailInFaults= true, 
    UseSynchronizationContext=true,
    ValidateMustUnderstand=true
  )]
  public class Client : SampleDuplexHelloCallback
  {
    AutoResetEvent waitHandle;

    public Client()
    {
      waitHandle = new AutoResetEvent(false);
    }

    public void Run()
    {
      // Picks up configuration from the configuration file.
      SampleDuplexHelloClient wcfClient
        = new SampleDuplexHelloClient(new InstanceContext(this), "WSDualHttpBinding_SampleDuplexHello");
      try
      {
        Console.ForegroundColor = ConsoleColor.White;
        Console.WriteLine("Enter a greeting to send and press ENTER: ");
        Console.Write(">>> ");
        Console.ForegroundColor = ConsoleColor.Green;
        string greeting = Console.ReadLine();
        Console.ForegroundColor = ConsoleColor.White;
        Console.WriteLine("Called service with: \r\n\t" + greeting);
        wcfClient.Hello(greeting);
        Console.WriteLine("Execution passes service call and moves to the WaitHandle.");
        this.waitHandle.WaitOne();
        Console.ForegroundColor = ConsoleColor.Blue;
        Console.WriteLine("Set was called.");
        Console.Write("Press ");
        Console.ForegroundColor = ConsoleColor.Red;
        Console.Write("ENTER");
        Console.ForegroundColor = ConsoleColor.Blue;
        Console.Write(" to exit...");
        Console.ReadLine();
      }
      catch (TimeoutException timeProblem)
      {
        Console.WriteLine("The service operation timed out. " + timeProblem.Message);
        Console.ReadLine();
      }
      catch (CommunicationException commProblem)
      {
        Console.WriteLine("There was a communication problem. " + commProblem.Message);
        Console.ReadLine();
      }
    }
    public static void Main()
    {
      Client client = new Client();
      client.Run();
    }

    public void Reply(string response)
    {
      Console.WriteLine("Received output.");
      Console.WriteLine("\r\n\t" + response);
      this.waitHandle.Set();
    }
  }
}

.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

.NET for Windows Store apps

Supported in: Windows 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.
Show:
© 2014 Microsoft