DuplexClientBase<TChannel> 类

定义

用于创建双工服务的通道,并将该通道与回调对象相关联。

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

要创建的通道类型。

继承
DuplexClientBase<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(和/或 OnAbort)中,而不是放入析构函数中。

  • 避免使用析构函数:它们会导致编译器自动生成 IDisposable

  • 避免使用非引用成员:它们可能会导致编译器自动生成 IDisposable

  • 避免使用终结器;但如果包含一个终结器,则应该禁止显示生成警告并从 (On)(Begin)Close(和/或 OnAbort)调用 SuppressFinalize(Object) 和终结器本身,以便模拟自动生成的 IDisposable 行为。

构造函数

DuplexClientBase<TChannel>(InstanceContext)

使用指定的回调对象初始化 DuplexClientBase<TChannel> 类的新实例。

DuplexClientBase<TChannel>(InstanceContext, Binding, EndpointAddress)

使用指定的回调对象、绑定和服务终结点地址初始化 DuplexClientBase<TChannel> 类的新实例。

DuplexClientBase<TChannel>(InstanceContext, ServiceEndpoint)

使用指定的回调对象和服务终结点初始化 DuplexClientBase<TChannel> 类的新实例。

DuplexClientBase<TChannel>(InstanceContext, String)

使用指定的回调对象和配置名称初始化 DuplexClientBase<TChannel> 类的新实例。

DuplexClientBase<TChannel>(InstanceContext, String, EndpointAddress)

使用指定的回调对象、配置名称和服务终结点地址初始化 DuplexClientBase<TChannel> 类的新实例。

DuplexClientBase<TChannel>(InstanceContext, String, String)

使用指定的回调对象、配置名称和服务终结点地址初始化 DuplexClientBase<TChannel> 类的新实例。

DuplexClientBase<TChannel>(Object)

使用指定的回调对象初始化 DuplexClientBase<TChannel> 类的新实例。

DuplexClientBase<TChannel>(Object, Binding, EndpointAddress)

使用指定的回调对象、绑定和服务终结点地址初始化 DuplexClientBase<TChannel> 类的新实例。

DuplexClientBase<TChannel>(Object, ServiceEndpoint)

使用指定的回调对象和服务终结点初始化 DuplexClientBase<TChannel> 类的新实例。

DuplexClientBase<TChannel>(Object, String)

使用指定的回调对象和配置名称初始化 DuplexClientBase<TChannel> 类的新实例。

DuplexClientBase<TChannel>(Object, String, EndpointAddress)

使用指定的回调对象、配置名称和服务终结点地址初始化 DuplexClientBase<TChannel> 类的新实例。

DuplexClientBase<TChannel>(Object, String, String)

使用指定的回调对象、终结点配置名称和服务终结点地址初始化 DuplexClientBase<TChannel> 类的新实例。

属性

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>)
OpenAsync()

用于创建双工服务的通道,并将该通道与回调对象相关联。

(继承自 ClientBase<TChannel>)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

显式接口实现

IAsyncDisposable.DisposeAsync()

用于创建双工服务的通道,并将该通道与回调对象相关联。

(继承自 ClientBase<TChannel>)
ICommunicationObject.BeginClose(AsyncCallback, Object)

开始一个关闭 ClientBase<TChannel> 的异步操作。

(继承自 ClientBase<TChannel>)
ICommunicationObject.BeginClose(TimeSpan, AsyncCallback, Object)

开始一个在指定超时内关闭 ClientBase<TChannel> 的异步操作。

(继承自 ClientBase<TChannel>)
ICommunicationObject.BeginOpen(AsyncCallback, Object)

开始一个打开 ClientBase<TChannel> 对象的异步操作。

(继承自 ClientBase<TChannel>)
ICommunicationObject.BeginOpen(TimeSpan, AsyncCallback, Object)

开始一个在指定时间间隔内打开 ClientBase<TChannel> 对象的异步操作。

(继承自 ClientBase<TChannel>)
ICommunicationObject.Close()

使通信对象从其当前状态转换到关闭状态。

(继承自 ClientBase<TChannel>)
ICommunicationObject.Close(TimeSpan)

使 ClientBase<TChannel> 对象从其当前状态转换到关闭状态。

(继承自 ClientBase<TChannel>)
ICommunicationObject.Closed

ClientBase<TChannel> 对象已经从其当前状态转换到已关闭状态时调用的事件处理程序。

(继承自 ClientBase<TChannel>)
ICommunicationObject.Closing

ClientBase<TChannel> 对象从其当前状态转换到已关闭状态时调用的事件处理程序。

(继承自 ClientBase<TChannel>)
ICommunicationObject.EndClose(IAsyncResult)

完成一个关闭 ClientBase<TChannel> 对象的异步操作。

(继承自 ClientBase<TChannel>)
ICommunicationObject.EndOpen(IAsyncResult)

完成一个打开 ClientBase<TChannel> 对象的异步操作。

(继承自 ClientBase<TChannel>)
ICommunicationObject.Faulted

在对 ClientBase<TChannel> 对象执行操作过程中发生错误时调用的事件处理程序。

(继承自 ClientBase<TChannel>)
ICommunicationObject.Open()

使通信对象从已创建状态转换到已打开状态。

(继承自 ClientBase<TChannel>)
ICommunicationObject.Open(TimeSpan)

使 ClientBase<TChannel> 对象在指定的时间间隔内从已创建状态转换到已打开状态。

(继承自 ClientBase<TChannel>)
ICommunicationObject.Opened

ClientBase<TChannel> 对象从已创建状态转换为已打开状态时调用的事件处理程序。

(继承自 ClientBase<TChannel>)
ICommunicationObject.Opening

ClientBase<TChannel> 对象从已创建状态转换为已打开状态时调用的事件处理程序。

(继承自 ClientBase<TChannel>)
IDisposable.Dispose()

Dispose() 方法的显式实现。

(继承自 ClientBase<TChannel>)

扩展方法

CloseHelperAsync(ICommunicationObject, TimeSpan)

用于创建双工服务的通道,并将该通道与回调对象相关联。

OpenHelperAsync(ICommunicationObject, TimeSpan)

用于创建双工服务的通道,并将该通道与回调对象相关联。

ConfigureAwait(IAsyncDisposable, Boolean)

配置如何执行从异步可处置项返回的任务的等待。

适用于