DuplexClientBase<TChannel> 類別

定義

用來建立雙工服務的通道,並將該通道與回呼物件產生關聯。Used to create a channel to a duplex service and associate that channel with a callback object.

generic <typename TChannel>
 where TChannel : classpublic ref class DuplexClientBase abstract : System::ServiceModel::ClientBase<TChannel>
generic <typename TChannel>
 where TChannel : classpublic ref class DuplexClientBase : System::ServiceModel::ClientBase<TChannel>
public abstract class DuplexClientBase<TChannel> : System.ServiceModel.ClientBase<TChannel> where TChannel : class
public 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)
Public Class DuplexClientBase(Of TChannel)
Inherits ClientBase(Of TChannel)

類型參數

TChannel

要建立的通道類型。The type of the channel to be created.

繼承
DuplexClientBase<TChannel>

範例

下列範例示範如何在雙工 WCF 用戶端類型的用戶端(SampleDuplexHelloClient)中使用,以回呼物件傳遞新的 System.ServiceModel.InstanceContext 物件以接聽回呼。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();
    }
  }
}

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> 類別來建立可指定回呼物件的服務通道。Use the DuplexClientBase<TChannel> class to create a channel to a service that specifies a callback object. DuplexClientBase<TChannel> 物件會包裝 System.ServiceModel.DuplexChannelFactory<TChannel> 物件,以提供 WCF 物件的連接。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.

給衍生自此類別之 Managed C++ 使用者的特別說明:Special note for Managed C++ users deriving from this class:

  • 請將您的清除程式碼置於 (On)(Begin)Close (and/or OnAbort),而不是解構函式。Put your cleanup code in (On)(Begin)Close (and/or OnAbort), not in a destructor.

  • 避免使用解構函式:它們會導致編譯器自動產生 IDisposableAvoid destructors: they cause the compiler to auto-generate IDisposable

  • 避免使用非參考成員:它們會導致編譯器自動產生 IDisposableAvoid non-reference members: they can cause the compiler to auto-generate IDisposable

  • 避免使用完成項;但是假如您加入一個完成項,就應該抑制建置警告並呼叫來自 (On)(Begin)Close (and/or OnAbort) 的 SuppressFinalize(Object) 和完成項,以模擬原本可能自動產生的 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.

建構函式

DuplexClientBase<TChannel>(InstanceContext)

使用指定的回呼物件來初始化 DuplexClientBase<TChannel> 類別的新執行個體。Initializes a new instance of the DuplexClientBase<TChannel> class using the specified callback object.

DuplexClientBase<TChannel>(InstanceContext, Binding, EndpointAddress)

使用指定的回呼物件、繫結以及服務端點位址來初始化 DuplexClientBase<TChannel> 類別的新執行個體。Initializes a new instance of the DuplexClientBase<TChannel> class using the specified callback object, binding, and service endpoint address.

DuplexClientBase<TChannel>(InstanceContext, ServiceEndpoint)

使用指定的回呼物件與服務端點,初始化 DuplexClientBase<TChannel> 類別的新執行個體。Initializes a new instance of the DuplexClientBase<TChannel> class with the specified callback object and service endpoint.

DuplexClientBase<TChannel>(InstanceContext, String)

使用指定的回呼物件與組態名稱來初始化 DuplexClientBase<TChannel> 類別的新執行個體。Initializes a new instance of the DuplexClientBase<TChannel> class using the specified callback object and configuration name.

DuplexClientBase<TChannel>(InstanceContext, String, EndpointAddress)

使用指定的回呼物件、組態名稱以及服務端點位址,初始化 DuplexClientBase<TChannel> 類別的新執行個體。Initializes a new instance of the DuplexClientBase<TChannel> class using the specified callback object, configuration name, and service endpoint address.

DuplexClientBase<TChannel>(InstanceContext, String, String)

使用指定的回呼物件、組態名稱以及服務端點位址,初始化 DuplexClientBase<TChannel> 類別的新執行個體。Initializes a new instance of the DuplexClientBase<TChannel> class using the specified callback object, configuration name, and service endpoint address.

DuplexClientBase<TChannel>(Object)

使用指定的回呼物件來初始化 DuplexClientBase<TChannel> 類別的新執行個體。Initializes a new instance of the DuplexClientBase<TChannel> class using the specified callback object.

DuplexClientBase<TChannel>(Object, Binding, EndpointAddress)

使用指定的回呼物件、繫結以及服務端點位址來初始化 DuplexClientBase<TChannel> 類別的新執行個體。Initializes a new instance of the DuplexClientBase<TChannel> class using the specified callback object, binding, and service endpoint address.

DuplexClientBase<TChannel>(Object, ServiceEndpoint)

使用指定的回呼物件與服務端點,初始化 DuplexClientBase<TChannel> 類別的新執行個體。Initializes a new instance of the DuplexClientBase<TChannel> class with the specified callback object and service endpoint.

DuplexClientBase<TChannel>(Object, String)

使用指定的回呼物件與組態名稱來初始化 DuplexClientBase<TChannel> 類別的新執行個體。Initializes a new instance of the DuplexClientBase<TChannel> class using the specified callback object and configuration name.

DuplexClientBase<TChannel>(Object, String, EndpointAddress)

使用指定的回呼物件、組態名稱以及服務端點位址,初始化 DuplexClientBase<TChannel> 類別的新執行個體。Initializes a new instance of the DuplexClientBase<TChannel> class using the specified callback object, configuration name, and service endpoint address.

DuplexClientBase<TChannel>(Object, String, String)

使用指定的回呼物件、端點組態名稱以及服務端點位址來初始化 DuplexClientBase<TChannel> 類別的新執行個體。Initializes a new instance of the DuplexClientBase<TChannel> class using the specified callback object, endpoint configuration name, and service endpoint address.

屬性

Channel

取得用來傳送訊息至多種不同設定服務端點的內部通道。Gets the inner channel used to send messages to variously configured service endpoints.

(繼承來源 ClientBase<TChannel>)
ChannelFactory

取得基礎 ChannelFactory<TChannel> 物件。Gets the underlying ChannelFactory<TChannel> object.

(繼承來源 ClientBase<TChannel>)
ClientCredentials

取得用來呼叫作業的用戶端認證。Gets the client credentials used to call an operation.

(繼承來源 ClientBase<TChannel>)
Endpoint

取得 WCF 用戶端可連線之服務的目標端點。Gets the target endpoint for the service to which the WCF client can connect.

(繼承來源 ClientBase<TChannel>)
InnerChannel

取得基礎 IClientChannel 實作。Gets the underlying IClientChannel implementation.

(繼承來源 ClientBase<TChannel>)
InnerDuplexChannel

取得雙面通道的底層 IClientChannel 實作。Gets the underlying IClientChannel implementation for the duplex channel.

State

取得 ClientBase<TChannel> 物件的目前狀態。Gets the current state of the ClientBase<TChannel> object.

(繼承來源 ClientBase<TChannel>)

方法

Abort()

導致 ClientBase<TChannel> 物件從目前的狀態立即轉換為已關閉狀態。Causes the ClientBase<TChannel> object to transition immediately from its current state into the closed state.

(繼承來源 ClientBase<TChannel>)
Close()

導致 ClientBase<TChannel> 物件從目前的狀態轉換為已關閉狀態。Causes the ClientBase<TChannel> object to transition from its current state into the closed state.

(繼承來源 ClientBase<TChannel>)
CreateChannel()

傳回與回呼物件 (已傳遞至建構函式) 相關聯的服務通道。Returns a channel to the service associated with the callback object passed to the constructor.

CreateChannel()

傳回服務的新通道。Returns a new channel to the service.

(繼承來源 ClientBase<TChannel>)
DisplayInitializationUI()

如果需要使用者介面來初始化通道才能使用,會先指示該通道顯示使用者介面。Instructs the inner channel to display a user interface if one is required to initialize the channel prior to using it.

(繼承來源 ClientBase<TChannel>)
Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetDefaultValueForInitialization<T>()

以 C# 複製預設關鍵字的行為。Replicates the behavior of the default keyword in C#.

(繼承來源 ClientBase<TChannel>)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
InvokeAsync(ClientBase<TChannel>.BeginOperationDelegate, Object[], ClientBase<TChannel>.EndOperationDelegate, SendOrPostCallback, Object)

提供實作事件架構非同步模式的支援。Provides support for implementing the event-based asynchronous pattern. 如需此模式的詳細資訊,請參閱事件架構非同步模式概觀For more information about this pattern, see Event-based Asynchronous Pattern Overview.

(繼承來源 ClientBase<TChannel>)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
Open()

導致 ClientBase<TChannel> 物件從已建立狀態轉換為已開啟狀態。Causes the ClientBase<TChannel> object to transition from the created state into the opened state.

(繼承來源 ClientBase<TChannel>)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

明確介面實作

ICommunicationObject.BeginClose(AsyncCallback, Object)

開始非同步作業以關閉 ClientBase<TChannel>Begins an asynchronous operation to close the ClientBase<TChannel>.

(繼承來源 ClientBase<TChannel>)
ICommunicationObject.BeginClose(TimeSpan, AsyncCallback, Object)

開始非同步作業以關閉具有指定逾時的 ClientBase<TChannel>Begins an asynchronous operation to close the ClientBase<TChannel> with a specified timeout.

(繼承來源 ClientBase<TChannel>)
ICommunicationObject.BeginOpen(AsyncCallback, Object)

開始非同步作業以開啟 ClientBase<TChannel> 物件。Begins an asynchronous operation to open the ClientBase<TChannel> object.

(繼承來源 ClientBase<TChannel>)
ICommunicationObject.BeginOpen(TimeSpan, AsyncCallback, Object)

開始非同步作業以在指定的時間間隔內開啟 ClientBase<TChannel> 物件。Begins an asynchronous operation to open the ClientBase<TChannel> object within a specified interval of time.

(繼承來源 ClientBase<TChannel>)
ICommunicationObject.Close() (繼承來源 ClientBase<TChannel>)
ICommunicationObject.Close(TimeSpan)

導致 ClientBase<TChannel> 物件從目前的狀態轉換為已關閉狀態。Causes the ClientBase<TChannel> object to transition from its current state into the closed state.

(繼承來源 ClientBase<TChannel>)
ICommunicationObject.Closed

ClientBase<TChannel> 物件從目前狀態轉換為已關閉狀態時叫用的事件處理常式。The event handler that is invoked when the ClientBase<TChannel> object has transitioned from its current state to the closed state.

(繼承來源 ClientBase<TChannel>)
ICommunicationObject.Closing

ClientBase<TChannel> 物件從目前狀態轉換為已關閉狀態時叫用的事件處理常式。The event handler that is invoked when the ClientBase<TChannel> object transitions from its current state to the closed state.

(繼承來源 ClientBase<TChannel>)
ICommunicationObject.EndClose(IAsyncResult)

完成非同步作業以關閉 ClientBase<TChannel> 物件。Completes an asynchronous operation to close the ClientBase<TChannel> object.

(繼承來源 ClientBase<TChannel>)
ICommunicationObject.EndOpen(IAsyncResult)

完成非同步作業以開啟 ClientBase<TChannel> 物件。Completes an asynchronous operation to open the ClientBase<TChannel> object.

(繼承來源 ClientBase<TChannel>)
ICommunicationObject.Faulted

在針對 ClientBase<TChannel> 物件執行作業發生錯誤時叫用的事件處理常式。The event handler that is invoked when a fault occurs while performing an operation on the ClientBase<TChannel> object.

(繼承來源 ClientBase<TChannel>)
ICommunicationObject.Open() (繼承來源 ClientBase<TChannel>)
ICommunicationObject.Open(TimeSpan)

在指定時間間隔內,導致 ClientBase<TChannel> 物件從已建立狀態轉換為已開啟狀態。Causes the ClientBase<TChannel> object to transition from the created state into the opened state within a specified interval of time.

(繼承來源 ClientBase<TChannel>)
ICommunicationObject.Opened

ClientBase<TChannel> 物件從已建立狀態轉換為已開啟狀態時叫用的事件處理常式。The event handler that is invoked when the ClientBase<TChannel> object transitions from the created state to the opened state.

(繼承來源 ClientBase<TChannel>)
ICommunicationObject.Opening

ClientBase<TChannel> 物件從已建立狀態轉換為已開啟狀態時叫用的事件處理常式。The event handler that is invoked when the ClientBase<TChannel> object transitions from the created state to the opened state.

(繼承來源 ClientBase<TChannel>)
IDisposable.Dispose()

Dispose() 方法的明確實作。Explicit implementation of the Dispose() method.

(繼承來源 ClientBase<TChannel>)

適用於