語言

ClientBase<TChannel> 建構函式

定義

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

多載

名稱 Description
ClientBase<TChannel>()

使用應用程式設定檔中的預設目標端點初始化該 ClientBase<TChannel> 類別的新實例。

ClientBase<TChannel>(InstanceContext, String, String)

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

ClientBase<TChannel>(InstanceContext, Binding, EndpointAddress)

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

ClientBase<TChannel>(String, String)

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

ClientBase<TChannel>(String, EndpointAddress)

利用指定的目標位址與端點資訊初始化該 ClientBase<TChannel> 類別的新實例。

ClientBase<TChannel>(InstanceContext, String)

利用指定的回調服務與端點設定資訊初始化該 ClientBase<TChannel> 類別的新實例。

ClientBase<TChannel>(InstanceContext, String, EndpointAddress)

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

ClientBase<TChannel>(Binding, EndpointAddress)

使用指定的綁定與目標位址初始化該類別的新實例 ClientBase<TChannel> 。

ClientBase<TChannel>(String)

利用應用程式設定檔ClientBase<TChannel>中指定的設定資訊初始化該endpointConfigurationName類別的新實例。

ClientBase<TChannel>(InstanceContext)

在雙工對話中,使用 作為ClientBase<TChannel>回調物件,初始化該類別的新callbackInstance實例。

ClientBase<TChannel>(ServiceEndpoint)

使用指定的 ClientBase<TChannel>初始化類別的新實例ServiceEndpoint。

ClientBase<TChannel>(InstanceContext, ServiceEndpoint)

使用指定的 ClientBase<TChannel> 和 InstanceContext 物件初始化該類別的新實例ServiceEndpoint。

備註

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

ClientBase<TChannel>()

來源:
ClientBase.cs
來源:
ClientBase.cs
來源:
ClientBase.cs

使用應用程式設定檔中的預設目標端點初始化該 ClientBase<TChannel> 類別的新實例。

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

例外狀況

要麼設定檔中沒有預設端點資訊,要麼檔案中有多個端點,或是沒有設定檔。

範例

以下程式碼範例展示了客戶端如何在擴展ClientBase<TChannel>該類別的類別中使用此建構子SampleServiceClient。

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 callbackInstance, string endpointConfigurationName, string remoteAddress);
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)

參數

callbackInstance
InstanceContext

客戶端用來監聽連接服務訊息的回調物件。

endpointConfigurationName
String

應用程式設定檔中端點名稱。

remoteAddress
String

服務的地址。

例外狀況

回調實例, endpointConfigurationName或 remoteAddress 為 null。

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

備註

使用此建構器傳遞一個實作目標服務回調合約的服務物件,並從應用程式設定檔中的端點名稱(目標值可透過尋找 name 用戶端 <端點> 元素的屬性找到)及指定位址來決定目標端點資訊。

另請參閱

適用於

ClientBase<TChannel>(InstanceContext, Binding, EndpointAddress)

來源:
ClientBase.cs
來源:
ClientBase.cs
來源:
ClientBase.cs

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

protected:
 ClientBase(System::ServiceModel::InstanceContext ^ callbackInstance, System::ServiceModel::Channels::Binding ^ binding, System::ServiceModel::EndpointAddress ^ remoteAddress);
protected ClientBase(System.ServiceModel.InstanceContext callbackInstance, 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)>
Protected Sub New (callbackInstance As InstanceContext, binding As Binding, remoteAddress As EndpointAddress)

參數

callbackInstance
InstanceContext

回電服務。

binding
Binding

召喚禮拜的約束力。

remoteAddress
EndpointAddress

服務端點的位址。

例外狀況

回調實例, binding或 remoteAddress 為 null。

適用於

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

服務的地址。

例外狀況

endpointConfigurationName 或 remoteAddress 為 null。

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

備註

使用此建構子可從應用程式設定檔中的終端名稱(目標值可透過尋找 name 用戶端 <端點> 元素的屬性找到)及指定位址來決定目標端點資訊。

另請參閱

適用於

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

服務的地址。

例外狀況

endpointConfigurationName 或 remoteAddress 為 null。

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

備註

使用此建構子可從應用程式設定檔中的終端名稱(目標值可透過尋找 name 用戶端 <端點> 元素的屬性找到)及指定位址來決定目標端點資訊。

適用於

ClientBase<TChannel>(InstanceContext, String)

利用指定的回調服務與端點設定資訊初始化該 ClientBase<TChannel> 類別的新實例。

protected:
 ClientBase(System::ServiceModel::InstanceContext ^ callbackInstance, System::String ^ endpointConfigurationName);
protected ClientBase(System.ServiceModel.InstanceContext callbackInstance, string endpointConfigurationName);
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)

參數

callbackInstance
InstanceContext

客戶端用來監聽連接服務訊息的回調物件。

endpointConfigurationName
String

應用程式設定檔中端點名稱。

例外狀況

回調實例或 endpointConfigurationName 為 null。

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

備註

使用此建構子傳遞一個實作目標服務回調合約的服務物件,並從用戶端應用程式設定檔中決定目標端點資訊。 目標值是透過尋找 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 callbackInstance, 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)>
Protected Sub New (callbackInstance As InstanceContext, endpointConfigurationName As String, remoteAddress As EndpointAddress)

參數

callbackInstance
InstanceContext

客戶端用來監聽連接服務訊息的回調物件。

endpointConfigurationName
String

應用程式設定檔中端點名稱。

remoteAddress
EndpointAddress

服務的地址。

例外狀況

回調實例, endpointConfigurationName或 remoteAddress 為 null。

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

備註

使用此建構器傳遞一個實作目標服務回調合約的服務物件,並從應用程式設定檔中的端點名稱(目標值可透過尋找 name 用戶端 <端點> 元素的屬性找到)及指定位址來決定目標端點資訊。

另請參閱

適用於

ClientBase<TChannel>(Binding, EndpointAddress)

來源:
ClientBase.cs
來源:
ClientBase.cs
來源:
ClientBase.cs

使用指定的綁定與目標位址初始化該類別的新實例 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

服務端點的位址。

例外狀況

binding 或 remoteAddress 為 null。

適用於

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

來源:
ClientBase.cs
來源:
ClientBase.cs

在雙工對話中,使用 作為ClientBase<TChannel>回調物件,初始化該類別的新callbackInstance實例。

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

參數

callbackInstance
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>(ServiceEndpoint)

來源:
ClientBase.cs
來源:
ClientBase.cs
來源:
ClientBase.cs

使用指定的 ClientBase<TChannel>初始化類別的新實例ServiceEndpoint。

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>(InstanceContext, ServiceEndpoint)

使用指定的 ClientBase<TChannel> 和 InstanceContext 物件初始化該類別的新實例ServiceEndpoint。

protected:
 ClientBase(System::ServiceModel::InstanceContext ^ callbackInstance, System::ServiceModel::Description::ServiceEndpoint ^ endpoint);
protected ClientBase(System.ServiceModel.InstanceContext callbackInstance, 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)>
Protected Sub New (callbackInstance As InstanceContext, endpoint As ServiceEndpoint)

參數

callbackInstance
InstanceContext

客戶端應用程式用來監聽連接服務訊息的回調物件。

endpoint
ServiceEndpoint

服務端點允許用戶端找到並與該服務溝通。

適用於