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 物件的連線能力。 您可以使用任何一種型別來連接雙工服務。 如需雙工服務的詳細資訊,請參閱雙工服務

給衍生自此類別之 Managed C++ 使用者的特別說明:

  • 請將您的清除程式碼置於 (On)(Begin)Close (and/or OnAbort),而不是解構函式。

  • 避免使用解構函式:它們會導致編譯器自動產生 IDisposable

  • 避免使用非參考成員:它們會導致編譯器自動產生 IDisposable

  • 避免使用完成項;但是假如您加入一個完成項,就應該抑制建置警告並呼叫來自 (On)(Begin)Close (and/or 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)

用於建立雙工服務通道並將該通道與回呼物件相關聯。

適用於