ClientBase<TChannel> 构造函数

定义

初始化 ClientBase<TChannel> 类的新实例。

重载

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)

使用指定的 InstanceContextServiceEndpoint 对象初始化 ClientBase<TChannel> 类的新实例。

注解

使用 根据应用程序配置文件中的终结点信息创建 WCF 客户端对象。 该构造函数的主要功能是创建 System.ServiceModel.ChannelFactory<TChannel>,其中类型参数为目标服务协定的类型。

ClientBase<TChannel>()

Source:
ClientBase.cs
Source:
ClientBase.cs
Source:
ClientBase.cs

使用应用程序配置文件中的默认目标终结点初始化 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 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

服务的地址。

例外

回叫实例 endpointConfigurationNameremoteAddressnull

无法找到终结点或者终结点协定无效。

注解

使用此构造函数传递实现目标服务的回调协定的服务对象,并从应用程序配置文件中的终结点名称确定目标终结点信息 (目标值是通过查找 name 客户端 <终结点> 元素) 的属性和指定的地址来定位的。

另请参阅

适用于

ClientBase<TChannel>(InstanceContext, Binding, EndpointAddress)

Source:
ClientBase.cs
Source:
ClientBase.cs
Source:
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

服务终结点的地址。

例外

回叫实例 bindingremoteAddressnull

适用于

ClientBase<TChannel>(String, String)

Source:
ClientBase.cs
Source:
ClientBase.cs

初始化 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>(String, EndpointAddress)

Source:
ClientBase.cs
Source:
ClientBase.cs

使用指定的目标地址和终结点信息初始化 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 客户端 <终结点> 元素) 属性和指定地址来定位的。

适用于

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

应用程序配置文件中的终结点的名称。

例外

回叫实例或 endpointConfigurationNamenull

无法找到终结点或者终结点协定无效。

注解

使用此构造函数传递实现目标服务的回调协定的服务对象,并通过客户端应用程序配置文件确定目标终结点信息。 通过查找 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

服务的地址。

例外

回叫实例 endpointConfigurationNameremoteAddressnull

无法找到终结点或者终结点协定无效。

注解

使用此构造函数传递实现目标服务的回调协定的服务对象,并从应用程序配置文件中的终结点名称确定目标终结点信息 (目标值是通过查找 name 客户端 <终结点> 元素) 的属性和指定的地址来定位的。

另请参阅

适用于

ClientBase<TChannel>(Binding, EndpointAddress)

Source:
ClientBase.cs
Source:
ClientBase.cs
Source:
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

服务终结点的地址。

例外

bindingremoteAddressnull

适用于

ClientBase<TChannel>(String)

Source:
ClientBase.cs
Source:
ClientBase.cs

使用应用程序配置文件中由 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<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)

Source:
ClientBase.cs
Source:
ClientBase.cs
Source:
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)

使用指定的 InstanceContextServiceEndpoint 对象初始化 ClientBase<TChannel> 类的新实例。

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

允许客户端查找并与服务通信的服务的终结点。

适用于