ClientBase<TChannel> 建構函式

定義

初始化 ClientBase<TChannel> 類別的新執行個體。

多載

ClientBase<TChannel>()

使用應用程式組態檔中的預設目標端點,初始化 ClientBase<TChannel> 類別的新執行個體。

ClientBase<TChannel>(InstanceContext, String, String)

初始化 ClientBase<TChannel> 類別的新執行個體。

ClientBase<TChannel>(InstanceContext, String, EndpointAddress)

初始化 ClientBase<TChannel> 類別的新執行個體。

ClientBase<TChannel>(InstanceContext, String)

使用指定的回呼服務與端點組態資訊,初始化 ClientBase<TChannel> 類別的新執行個體。

ClientBase<TChannel>(InstanceContext, ServiceEndpoint)

使用指定的 ClientBase<TChannel>InstanceContext 物件,初始化 ServiceEndpoint 類別的新執行個體。

ClientBase<TChannel>(String, String)

初始化 ClientBase<TChannel> 類別的新執行個體。

ClientBase<TChannel>(InstanceContext, Binding, EndpointAddress)

初始化 ClientBase<TChannel> 類別的新執行個體。

ClientBase<TChannel>(InstanceContext)

在雙工對話中,使用 ClientBase<TChannel> 做為回呼物件來初始化 callbackInstance 類別的新執行個體。

ClientBase<TChannel>(Binding, EndpointAddress)

使用指定的繫結與目標位址,初始化 ClientBase<TChannel> 類別的新執行個體。

ClientBase<TChannel>(String)

使用由 ClientBase<TChannel> 在應用程式組態檔中指定的組態資訊,初始化 endpointConfigurationName 類別的新執行個體。

ClientBase<TChannel>(ServiceEndpoint)

使用指定的 ServiceEndpoint,初始化 ClientBase<TChannel> 類別的新執行個體。

ClientBase<TChannel>(String, EndpointAddress)

使用指定的目標位址與端點資訊,初始化 ClientBase<TChannel> 類別的新執行個體。

備註

使用 從應用程式組態檔中的端點資訊建立 WCF 用戶端物件。 建構函式的主要功能為建立 System.ServiceModel.ChannelFactory<TChannel>,其中型別參數為目標服務合約的型別。

ClientBase<TChannel>()

使用應用程式組態檔中的預設目標端點,初始化 ClientBase<TChannel> 類別的新執行個體。

protected:
 ClientBase();
protected ClientBase ();
Protected Sub New ()

例外狀況

組態檔中沒有預設端點資訊、檔案中的端點不只一個,或者沒有組態檔。

範例

下列程式碼範例說明用戶端如何在擴充 SampleServiceClient 類別的 ClientBase<TChannel> 類別中,使用此建構函式。

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

public class Client
{
  public static void Main()
  {
    // Picks up configuration from the config file.
    SampleServiceClient wcfClient = new SampleServiceClient();
    try
    {
        // Making calls.
        Console.WriteLine("Enter the greeting to send: ");
        string greeting = Console.ReadLine();
        Console.WriteLine("The service responded: " + wcfClient.SampleMethod(greeting));

        Console.WriteLine("Press ENTER to exit:");
        Console.ReadLine();

        // Done with service.
        wcfClient.Close();
        Console.WriteLine("Done!");
    }
    catch (TimeoutException timeProblem)
    {
      Console.WriteLine("The service operation timed out. " + timeProblem.Message);
      wcfClient.Abort();
      Console.Read();
    }
    catch(CommunicationException commProblem)
    {
      Console.WriteLine("There was a communication problem. " + commProblem.Message);
      wcfClient.Abort();
      Console.Read();
    }
  }
}


Imports System.ServiceModel
Imports System.ServiceModel.Channels

Public Class Client
  Public Shared Sub Main()
    ' Picks up configuration from the config file.
    Dim wcfClient As New SampleServiceClient()
    Try
        ' Making calls.
        Console.WriteLine("Enter the greeting to send: ")
            Dim greeting = Console.ReadLine()
        Console.WriteLine("The service responded: " & wcfClient.SampleMethod(greeting))

        Console.WriteLine("Press ENTER to exit:")
        Console.ReadLine()

        ' Done with service. 
        wcfClient.Close()
        Console.WriteLine("Done!")
    Catch timeProblem As TimeoutException
      Console.WriteLine("The service operation timed out. " & timeProblem.Message)
      wcfClient.Abort()
      Console.Read()
    Catch commProblem As CommunicationException
      Console.WriteLine("There was a communication problem. " & commProblem.Message)
      wcfClient.Abort()
      Console.Read()
    End Try
  End Sub
End Class

備註

使用此建構函式建立 WCF 用戶端物件來叫用服務。 這個建構函式會使用型別參數做為應用程式組態檔中的目標合約以及繫結程序和位址資訊。

適用於

ClientBase<TChannel>(InstanceContext, String, String)

初始化 ClientBase<TChannel> 類別的新執行個體。

protected:
 ClientBase(System::ServiceModel::InstanceContext ^ callbackInstance, System::String ^ endpointConfigurationName, System::String ^ remoteAddress);
protected:
 ClientBase(System::ServiceModel::InstanceContext ^ instance, System::String ^ endpointConfigurationName, System::String ^ remoteAddress);
protected ClientBase (System.ServiceModel.InstanceContext callbackInstance, string endpointConfigurationName, string remoteAddress);
protected ClientBase (System.ServiceModel.InstanceContext instance, string endpointConfigurationName, string remoteAddress);
new System.ServiceModel.ClientBase<'Channel (requires 'Channel : null)> : System.ServiceModel.InstanceContext * string * string -> System.ServiceModel.ClientBase<'Channel (requires 'Channel : null)>
new System.ServiceModel.ClientBase<'Channel (requires 'Channel : null)> : System.ServiceModel.InstanceContext * string * string -> System.ServiceModel.ClientBase<'Channel (requires 'Channel : null)>
Protected Sub New (callbackInstance As InstanceContext, endpointConfigurationName As String, remoteAddress As String)
Protected Sub New (instance As InstanceContext, endpointConfigurationName As String, remoteAddress As String)

參數

callbackInstanceinstance
InstanceContext

用戶端用來接聽來自已連線服務之訊息的回呼物件。

endpointConfigurationName
String

應用程式組態檔中端點的名稱。

remoteAddress
String

服務的位址。

例外狀況

回呼執行個體,endpointConfigurationNameremoteAddressnull

找不到端點,或端點合約無效。

備註

使用此建構函式來傳遞服務物件,該物件會實作目標服務的回呼合約,並從應用程式組態檔中的端點名稱判斷目標端點資訊, (目標值是尋找 name 用戶端 < 端點 > 元素的 屬性,) 和指定的位址。

另請參閱

適用於

ClientBase<TChannel>(InstanceContext, String, EndpointAddress)

初始化 ClientBase<TChannel> 類別的新執行個體。

protected:
 ClientBase(System::ServiceModel::InstanceContext ^ callbackInstance, System::String ^ endpointConfigurationName, System::ServiceModel::EndpointAddress ^ remoteAddress);
protected:
 ClientBase(System::ServiceModel::InstanceContext ^ instance, System::String ^ endpointConfigurationName, System::ServiceModel::EndpointAddress ^ remoteAddress);
protected ClientBase (System.ServiceModel.InstanceContext callbackInstance, string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress);
protected ClientBase (System.ServiceModel.InstanceContext instance, string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress);
new System.ServiceModel.ClientBase<'Channel (requires 'Channel : null)> : System.ServiceModel.InstanceContext * string * System.ServiceModel.EndpointAddress -> System.ServiceModel.ClientBase<'Channel (requires 'Channel : null)>
new System.ServiceModel.ClientBase<'Channel (requires 'Channel : null)> : System.ServiceModel.InstanceContext * string * System.ServiceModel.EndpointAddress -> System.ServiceModel.ClientBase<'Channel (requires 'Channel : null)>
Protected Sub New (callbackInstance As InstanceContext, endpointConfigurationName As String, remoteAddress As EndpointAddress)
Protected Sub New (instance As InstanceContext, endpointConfigurationName As String, remoteAddress As EndpointAddress)

參數

callbackInstanceinstance
InstanceContext

用戶端用來接聽來自已連線服務之訊息的回呼物件。

endpointConfigurationName
String

應用程式組態檔中端點的名稱。

remoteAddress
EndpointAddress

服務的位址。

例外狀況

回呼執行個體,endpointConfigurationNameremoteAddressnull

找不到端點,或端點合約無效。

備註

使用此建構函式來傳遞服務物件,該物件會實作目標服務的回呼合約,並從應用程式組態檔中的端點名稱判斷目標端點資訊, (目標值是尋找 name 用戶端 < 端點 > 元素的 屬性,) 和指定的位址。

另請參閱

適用於

ClientBase<TChannel>(InstanceContext, String)

使用指定的回呼服務與端點組態資訊,初始化 ClientBase<TChannel> 類別的新執行個體。

protected:
 ClientBase(System::ServiceModel::InstanceContext ^ callbackInstance, System::String ^ endpointConfigurationName);
protected:
 ClientBase(System::ServiceModel::InstanceContext ^ instance, System::String ^ endpointConfigurationName);
protected ClientBase (System.ServiceModel.InstanceContext callbackInstance, string endpointConfigurationName);
protected ClientBase (System.ServiceModel.InstanceContext instance, string endpointConfigurationName);
new System.ServiceModel.ClientBase<'Channel (requires 'Channel : null)> : System.ServiceModel.InstanceContext * string -> System.ServiceModel.ClientBase<'Channel (requires 'Channel : null)>
new System.ServiceModel.ClientBase<'Channel (requires 'Channel : null)> : System.ServiceModel.InstanceContext * string -> System.ServiceModel.ClientBase<'Channel (requires 'Channel : null)>
Protected Sub New (callbackInstance As InstanceContext, endpointConfigurationName As String)
Protected Sub New (instance As InstanceContext, endpointConfigurationName As String)

參數

callbackInstanceinstance
InstanceContext

用戶端用來接聽來自已連線服務之訊息的回呼物件。

endpointConfigurationName
String

應用程式組態檔中端點的名稱。

例外狀況

回呼執行個體或 endpointConfigurationNamenull

找不到端點,或端點合約無效。

備註

使用這個建構函式來傳遞可實作目標服務之回呼合約的服務物件,然後透過用戶端應用程式組態檔來決定目標端點資訊。 尋找用戶端 < 端點 > 元素的 屬性,以找出 name 目標值。

適用於

ClientBase<TChannel>(InstanceContext, ServiceEndpoint)

使用指定的 ClientBase<TChannel>InstanceContext 物件,初始化 ServiceEndpoint 類別的新執行個體。

protected:
 ClientBase(System::ServiceModel::InstanceContext ^ callbackInstance, System::ServiceModel::Description::ServiceEndpoint ^ endpoint);
protected:
 ClientBase(System::ServiceModel::InstanceContext ^ instance, System::ServiceModel::Description::ServiceEndpoint ^ endpoint);
protected ClientBase (System.ServiceModel.InstanceContext callbackInstance, System.ServiceModel.Description.ServiceEndpoint endpoint);
protected ClientBase (System.ServiceModel.InstanceContext instance, System.ServiceModel.Description.ServiceEndpoint endpoint);
new System.ServiceModel.ClientBase<'Channel (requires 'Channel : null)> : System.ServiceModel.InstanceContext * System.ServiceModel.Description.ServiceEndpoint -> System.ServiceModel.ClientBase<'Channel (requires 'Channel : null)>
new System.ServiceModel.ClientBase<'Channel (requires 'Channel : null)> : System.ServiceModel.InstanceContext * System.ServiceModel.Description.ServiceEndpoint -> System.ServiceModel.ClientBase<'Channel (requires 'Channel : null)>
Protected Sub New (callbackInstance As InstanceContext, endpoint As ServiceEndpoint)
Protected Sub New (instance As InstanceContext, endpoint As ServiceEndpoint)

參數

callbackInstanceinstance
InstanceContext

用戶端應用程式用來接聽來自已連線服務之訊息的回呼物件。

endpoint
ServiceEndpoint

服務的端點,可讓用戶端尋找並與服務通訊。

適用於

ClientBase<TChannel>(String, String)

初始化 ClientBase<TChannel> 類別的新執行個體。

protected:
 ClientBase(System::String ^ endpointConfigurationName, System::String ^ remoteAddress);
protected ClientBase (string endpointConfigurationName, string remoteAddress);
new System.ServiceModel.ClientBase<'Channel (requires 'Channel : null)> : string * string -> System.ServiceModel.ClientBase<'Channel (requires 'Channel : null)>
Protected Sub New (endpointConfigurationName As String, remoteAddress As String)

參數

endpointConfigurationName
String

應用程式組態檔中端點的名稱。

remoteAddress
String

服務的位址。

例外狀況

endpointConfigurationNameremoteAddressnull

找不到端點,或端點合約無效。

備註

使用此建構函式,從應用程式組態檔中的端點名稱判斷目標端點資訊, (尋找用戶端 < 端點 > 元素的屬性) 和指定的位址,以找出 name 目標值。

另請參閱

適用於

ClientBase<TChannel>(InstanceContext, Binding, EndpointAddress)

初始化 ClientBase<TChannel> 類別的新執行個體。

protected:
 ClientBase(System::ServiceModel::InstanceContext ^ callbackInstance, System::ServiceModel::Channels::Binding ^ binding, System::ServiceModel::EndpointAddress ^ remoteAddress);
protected:
 ClientBase(System::ServiceModel::InstanceContext ^ instance, System::ServiceModel::Channels::Binding ^ binding, System::ServiceModel::EndpointAddress ^ remoteAddress);
protected ClientBase (System.ServiceModel.InstanceContext callbackInstance, System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress);
protected ClientBase (System.ServiceModel.InstanceContext instance, System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress);
new System.ServiceModel.ClientBase<'Channel (requires 'Channel : null)> : System.ServiceModel.InstanceContext * System.ServiceModel.Channels.Binding * System.ServiceModel.EndpointAddress -> System.ServiceModel.ClientBase<'Channel (requires 'Channel : null)>
new System.ServiceModel.ClientBase<'Channel (requires 'Channel : null)> : System.ServiceModel.InstanceContext * System.ServiceModel.Channels.Binding * System.ServiceModel.EndpointAddress -> System.ServiceModel.ClientBase<'Channel (requires 'Channel : null)>
Protected Sub New (callbackInstance As InstanceContext, binding As Binding, remoteAddress As EndpointAddress)
Protected Sub New (instance As InstanceContext, binding As Binding, remoteAddress As EndpointAddress)

參數

callbackInstanceinstance
InstanceContext

回呼服務。

binding
Binding

用來呼叫服務的繫結。

remoteAddress
EndpointAddress

服務端點的位址。

例外狀況

回呼執行個體,bindingremoteAddressnull

適用於

ClientBase<TChannel>(InstanceContext)

在雙工對話中,使用 ClientBase<TChannel> 做為回呼物件來初始化 callbackInstance 類別的新執行個體。

protected:
 ClientBase(System::ServiceModel::InstanceContext ^ callbackInstance);
protected:
 ClientBase(System::ServiceModel::InstanceContext ^ instance);
protected ClientBase (System.ServiceModel.InstanceContext callbackInstance);
protected ClientBase (System.ServiceModel.InstanceContext instance);
new System.ServiceModel.ClientBase<'Channel (requires 'Channel : null)> : System.ServiceModel.InstanceContext -> System.ServiceModel.ClientBase<'Channel (requires 'Channel : null)>
new System.ServiceModel.ClientBase<'Channel (requires 'Channel : null)> : System.ServiceModel.InstanceContext -> System.ServiceModel.ClientBase<'Channel (requires 'Channel : null)>
Protected Sub New (callbackInstance As InstanceContext)
Protected Sub New (instance As InstanceContext)

參數

callbackInstanceinstance
InstanceContext

用戶端應用程式用來接聽來自已連線服務之訊息的回呼物件。

例外狀況

回呼執行個體為 null

組態檔中沒有預設端點資訊、檔案中的端點不只一個,或者沒有組態檔。

範例

下列程式碼範例說明如何使用這個具有 SampleDuplexHelloClient 類別的建構函式,傳遞接聽來自服務之訊息的回呼物件。

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

備註

當服務合約需要回呼服務執行個體時,請使用此建構函式。 目標端點是從應用程式組態檔中的型別參數和資訊所建構。

另請參閱

適用於

ClientBase<TChannel>(Binding, EndpointAddress)

使用指定的繫結與目標位址,初始化 ClientBase<TChannel> 類別的新執行個體。

protected:
 ClientBase(System::ServiceModel::Channels::Binding ^ binding, System::ServiceModel::EndpointAddress ^ remoteAddress);
protected ClientBase (System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress);
new System.ServiceModel.ClientBase<'Channel (requires 'Channel : null)> : System.ServiceModel.Channels.Binding * System.ServiceModel.EndpointAddress -> System.ServiceModel.ClientBase<'Channel (requires 'Channel : null)>
Protected Sub New (binding As Binding, remoteAddress As EndpointAddress)

參數

binding
Binding

用來呼叫服務的繫結。

remoteAddress
EndpointAddress

服務端點的位址。

例外狀況

bindingremoteAddressnull

適用於

ClientBase<TChannel>(String)

使用由 ClientBase<TChannel> 在應用程式組態檔中指定的組態資訊,初始化 endpointConfigurationName 類別的新執行個體。

protected:
 ClientBase(System::String ^ endpointConfigurationName);
protected ClientBase (string endpointConfigurationName);
new System.ServiceModel.ClientBase<'Channel (requires 'Channel : null)> : string -> System.ServiceModel.ClientBase<'Channel (requires 'Channel : null)>
Protected Sub New (endpointConfigurationName As String)

參數

endpointConfigurationName
String

應用程式組態檔中端點的名稱。

例外狀況

指定的端點資訊為 null

找不到端點,或端點合約無效。

備註

當應用程式組態檔的目標端點超過一個時,請使用此建構函式。 這個值是 name 用戶端 < 端點 > 專案的 屬性。

適用於

ClientBase<TChannel>(ServiceEndpoint)

使用指定的 ServiceEndpoint,初始化 ClientBase<TChannel> 類別的新執行個體。

protected:
 ClientBase(System::ServiceModel::Description::ServiceEndpoint ^ endpoint);
protected ClientBase (System.ServiceModel.Description.ServiceEndpoint endpoint);
new System.ServiceModel.ClientBase<'Channel (requires 'Channel : null)> : System.ServiceModel.Description.ServiceEndpoint -> System.ServiceModel.ClientBase<'Channel (requires 'Channel : null)>
Protected Sub New (endpoint As ServiceEndpoint)

參數

endpoint
ServiceEndpoint

服務的端點,可讓用戶端尋找並與服務通訊。

適用於

ClientBase<TChannel>(String, EndpointAddress)

使用指定的目標位址與端點資訊,初始化 ClientBase<TChannel> 類別的新執行個體。

protected:
 ClientBase(System::String ^ endpointConfigurationName, System::ServiceModel::EndpointAddress ^ remoteAddress);
protected ClientBase (string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress);
new System.ServiceModel.ClientBase<'Channel (requires 'Channel : null)> : string * System.ServiceModel.EndpointAddress -> System.ServiceModel.ClientBase<'Channel (requires 'Channel : null)>
Protected Sub New (endpointConfigurationName As String, remoteAddress As EndpointAddress)

參數

endpointConfigurationName
String

應用程式組態檔中端點的名稱。

remoteAddress
EndpointAddress

服務的位址。

例外狀況

endpointConfigurationNameremoteAddressnull

找不到端點,或端點合約無效。

備註

使用此建構函式,從應用程式組態檔中的端點名稱判斷目標端點資訊, (尋找用戶端 < 端點 > 元素的屬性) 和指定的位址,以找出 name 目標值。

適用於