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

Исходный код:
ClientBase.cs
Исходный код:
ClientBase.cs
Исходный код:
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 для вызова службы. Этот конструктор использует параметр type в качестве целевого контракта, а также сведения о привязке и адресе из файла конфигурации приложения.

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

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

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

Исключения

Экземпляр обратного вызова или endpointConfigurationNameremoteAddress является 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

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

Исключения

Экземпляр обратного вызова или bindingremoteAddress является 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

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

Исключения

Экземпляр обратного вызова или endpointConfigurationNameremoteAddress является 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

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

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