DuplexClientBase<TChannel> 类  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
用于创建双工服务的通道,并将该通道与回调对象相关联。
generic <typename TChannel>
 where TChannel : classpublic ref class DuplexClientBase abstract : System::ServiceModel::ClientBase<TChannel>
	public abstract class DuplexClientBase<TChannel> : System.ServiceModel.ClientBase<TChannel> where TChannel : class
	type DuplexClientBase<'Channel (requires 'Channel : null)> = class
    inherit ClientBase<'Channel (requires 'Channel : null)>
	Public MustInherit Class DuplexClientBase(Of TChannel)
Inherits ClientBase(Of TChannel)
    类型参数
- TChannel
 
要创建的通道的类型。
- 继承
 
示例
以下示例演示了在双工 WCF 客户端类型的客户端(SampleDuplexHelloClient)中使用,以使用回调对象传递新的 System.ServiceModel.InstanceContext 对象来侦听回调。
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();
    }
  }
}
Imports System.ServiceModel
Imports System.ServiceModel.Channels
Imports System.Threading
Namespace Microsoft.WCF.Documentation
  <CallbackBehaviorAttribute(IncludeExceptionDetailInFaults:= True, UseSynchronizationContext:=True, ValidateMustUnderstand:=True)> _
  Public Class Client
      Implements SampleDuplexHelloCallback
    Private waitHandle As AutoResetEvent
    Public Sub New()
      waitHandle = New AutoResetEvent(False)
    End Sub
    Public Sub Run()
      ' Picks up configuration from the configuration file.
      Dim wcfClient As New SampleDuplexHelloClient(New InstanceContext(Me), "WSDualHttpBinding_SampleDuplexHello")
      Try
        Console.ForegroundColor = ConsoleColor.White
        Console.WriteLine("Enter a greeting to send and press ENTER: ")
        Console.Write(">>> ")
        Console.ForegroundColor = ConsoleColor.Green
        Dim greeting As String = Console.ReadLine()
        Console.ForegroundColor = ConsoleColor.White
        Console.WriteLine("Called service with: " & Constants.vbCrLf & Constants.vbTab & greeting)
        wcfClient.Hello(greeting)
        Console.WriteLine("Execution passes service call and moves to the WaitHandle.")
        Me.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 timeProblem As TimeoutException
        Console.WriteLine("The service operation timed out. " & timeProblem.Message)
        Console.ReadLine()
      Catch commProblem As CommunicationException
        Console.WriteLine("There was a communication problem. " & commProblem.Message)
        Console.ReadLine()
      End Try
    End Sub
    Public Shared Sub Main()
      Dim client As New Client()
      client.Run()
    End Sub
    Public Sub Reply(ByVal response As String) Implements SampleDuplexHelloCallback.Reply
      Console.WriteLine("Received output.")
      Console.WriteLine(Constants.vbCrLf & Constants.vbTab & response)
      Me.waitHandle.Set()
    End Sub
  End Class
End Namespace
	注解
使用 DuplexClientBase<TChannel> 类创建指向指定回调对象的服务的通道。 DuplexClientBase<TChannel> 对象包装 System.ServiceModel.DuplexChannelFactory<TChannel> 对象,该对象提供 WCF 对象的连接。 可以使用任一类型连接到双工服务。 有关双工服务的详细信息,请参阅 双工服务。
从此类派生的托管C++用户的特殊说明:
将清理代码置于 (On)(Begin)Close(and/或 OnAbort),而不是析构函数中。
避免析构函数:它们会导致编译器自动生成 IDisposable
避免非引用成员:它们可能导致编译器自动生成 IDisposable
避免终结器;但是,如果包含生成警告,则应禁止生成警告并调用 SuppressFinalize(Object) 以及终结器本身(On)(Begin)Close(和/或 OnAbort),以模拟自动生成 IDisposable 行为是什么。
构造函数
属性
| Channel | 
		 获取用于将消息发送到各种配置的服务终结点的内部通道。 (继承自 ClientBase<TChannel>) | 
        	
| ChannelFactory | 
		 获取基础 ChannelFactory<TChannel> 对象。 (继承自 ClientBase<TChannel>) | 
        	
| ClientCredentials | 
		 获取用于调用操作的客户端凭据。 (继承自 ClientBase<TChannel>) | 
        	
| Endpoint | 
		 获取 WCF 客户端可连接到的服务的目标终结点。 (继承自 ClientBase<TChannel>) | 
        	
| InnerChannel | 
		 获取基础 IClientChannel 实现。 (继承自 ClientBase<TChannel>) | 
        	
| InnerDuplexChannel | 
		 获取双工通道的基础 IClientChannel 实现。  | 
        	
| State | 
		 获取 ClientBase<TChannel> 对象的当前状态。 (继承自 ClientBase<TChannel>) | 
        	
方法
| Abort() | 
		 使 ClientBase<TChannel> 对象立即从其当前状态转换为关闭状态。 (继承自 ClientBase<TChannel>) | 
        	
| Close() | 
		 使 ClientBase<TChannel> 对象从其当前状态转换为关闭状态。 (继承自 ClientBase<TChannel>) | 
        	
| CloseAsync() | 
		 用于创建双工服务的通道,并将该通道与回调对象相关联。 (继承自 ClientBase<TChannel>) | 
        	
| CreateChannel() | 
		 返回与传递给构造函数的回调对象关联的服务的通道。  | 
        	
| CreateChannel() | 
		 返回服务的新通道。 (继承自 ClientBase<TChannel>) | 
        	
| DisplayInitializationUI() | 
		 指示内部通道在使用前初始化通道时显示用户界面。 (继承自 ClientBase<TChannel>) | 
        	
| Equals(Object) | 
		 确定指定的对象是否等于当前对象。 (继承自 Object) | 
        	
| GetDefaultValueForInitialization<T>() | 
		 复制 C# 中默认关键字的行为。 (继承自 ClientBase<TChannel>) | 
        	
| GetHashCode() | 
		 用作默认哈希函数。 (继承自 Object) | 
        	
| GetType() | 
		 获取当前实例的 Type。 (继承自 Object) | 
        	
| InvokeAsync(ClientBase<TChannel>.BeginOperationDelegate, Object[], ClientBase<TChannel>.EndOperationDelegate, SendOrPostCallback, Object) | 
		 支持实现基于事件的异步模式。 有关此模式的详细信息,请参阅 基于事件的异步模式概述。 (继承自 ClientBase<TChannel>) | 
        	
| MemberwiseClone() | 
		 创建当前 Object的浅表副本。 (继承自 Object) | 
        	
| Open() | 
		 使 ClientBase<TChannel> 对象从创建的状态转换为打开状态。 (继承自 ClientBase<TChannel>) | 
        	
| ToString() | 
		 返回一个表示当前对象的字符串。 (继承自 Object) | 
        	
显式接口实现
扩展方法
| ConfigureAwait(IAsyncDisposable, Boolean) | 
		 配置如何执行从异步可释放项返回的任务的 await。  |