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)

Выполняет инициализацию нового экземпляра класса ClientBase<TChannel>, используя указанные объекты InstanceContext и ServiceEndpoint.

Комментарии

Используйте для создания клиентского объекта 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

Адрес службы.

Исключения

Экземпляр обратного вызова, endpointConfigurationName или remoteAddress имеет значение null.

Не удается найти конечную точку, или контракт конечной точки недопустим.

Комментарии

Используйте этот конструктор для передачи объекта службы, реализующего контракт обратного вызова для целевой службы, и определения сведений о целевой конечной точке из имени конечной точки в файле конфигурации приложения (целевое значение находится путем поиска 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

Адрес конечной точки службы.

Исключения

Экземпляр обратного вызова, binding или remoteAddress имеет значение null.

Применяется к

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

Адрес службы.

Исключения

Параметр endpointConfigurationName или remoteAddress имеет значение null.

Не удается найти конечную точку, или контракт конечной точки недопустим.

Комментарии

Используйте этот конструктор для определения сведений о целевой конечной точке из имени конечной точки в файле конфигурации приложения (целевое значение определяется путем поиска 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

Адрес службы.

Исключения

Параметр 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)

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

Адрес конечной точки службы.

Исключения

Параметр binding или remoteAddress имеет значение null.

Применяется к

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)

Выполняет инициализацию нового экземпляра класса 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

Конечная точка для службы, которая позволяет клиентам выполнять поиск и обмен данными со службой.

Применяется к