編輯

共用方式為


ClientBase<TChannel> Constructors

Definition

Initializes a new instance of the ClientBase<TChannel> class.

Overloads

ClientBase<TChannel>()

Initializes a new instance of the ClientBase<TChannel> class using the default target endpoint from the application configuration file.

ClientBase<TChannel>(InstanceContext, String, String)

Initializes a new instance of the ClientBase<TChannel> class.

ClientBase<TChannel>(InstanceContext, Binding, EndpointAddress)

Initializes a new instance of the ClientBase<TChannel> class.

ClientBase<TChannel>(String, String)

Initializes a new instance of the ClientBase<TChannel> class.

ClientBase<TChannel>(String, EndpointAddress)

Initializes a new instance of the ClientBase<TChannel> class using the specified target address and endpoint information.

ClientBase<TChannel>(InstanceContext, String)

Initializes a new instance of the ClientBase<TChannel> class using the specified callback service and endpoint configuration information.

ClientBase<TChannel>(InstanceContext, String, EndpointAddress)

Initializes a new instance of the ClientBase<TChannel> class.

ClientBase<TChannel>(Binding, EndpointAddress)

Initializes a new instance of the ClientBase<TChannel> class using the specified binding and target address.

ClientBase<TChannel>(String)

Initializes a new instance of the ClientBase<TChannel> class using the configuration information specified in the application configuration file by endpointConfigurationName.

ClientBase<TChannel>(InstanceContext)

Initializes a new instance of the ClientBase<TChannel> class using the callbackInstance as the callback object in a duplex conversation.

ClientBase<TChannel>(ServiceEndpoint)

Initializes a new instance of the ClientBase<TChannel> class using the specified ServiceEndpoint.

ClientBase<TChannel>(InstanceContext, ServiceEndpoint)

Initializes a new instance of the ClientBase<TChannel> class using the specified InstanceContext and ServiceEndpoint objects.

Remarks

Use to create a WCF client object from the endpoint information in the application configuration file. The main function of the constructor is to create a System.ServiceModel.ChannelFactory<TChannel> where the type parameter is the type of the target service contract.

ClientBase<TChannel>()

Source:
ClientBase.cs
Source:
ClientBase.cs

Initializes a new instance of the ClientBase<TChannel> class using the default target endpoint from the application configuration file.

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

Exceptions

Either there is no default endpoint information in the configuration file, more than one endpoint in the file, or no configuration file.

Examples

The following code example shows how a client uses this constructor in a SampleServiceClient class that extends the ClientBase<TChannel> class.

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

Remarks

Use this constructor to create a WCF client object to invoke a service. This constructor uses the type parameter as the target contract and the binding and address information from the application configuration file.

Applies to

ClientBase<TChannel>(InstanceContext, String, String)

Initializes a new instance of the ClientBase<TChannel> class.

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)

Parameters

callbackInstance
InstanceContext

The callback object that the client uses to listen for messages from the connected service.

endpointConfigurationName
String

The name of the endpoint in the application configuration file.

remoteAddress
String

The address of the service.

Exceptions

The callback instance, endpointConfigurationName, or remoteAddress is null.

The endpoint cannot be found or the endpoint contract is not valid.

Remarks

Use this constructor to pass a service object that implements the callback contract for the target service and determine the target endpoint information from the name of the endpoint in an application configuration file (The target value is located by finding the name attribute of the client <endpoint> element) and the specified address.

See also

Applies to

ClientBase<TChannel>(InstanceContext, Binding, EndpointAddress)

Source:
ClientBase.cs
Source:
ClientBase.cs

Initializes a new instance of the ClientBase<TChannel> class.

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)

Parameters

callbackInstance
InstanceContext

The callback service.

binding
Binding

The binding with which to call the service.

remoteAddress
EndpointAddress

The address of the service endpoint.

Exceptions

The callback instance, binding, or remoteAddress is null.

Applies to

ClientBase<TChannel>(String, String)

Initializes a new instance of the ClientBase<TChannel> class.

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)

Parameters

endpointConfigurationName
String

The name of the endpoint in the application configuration file.

remoteAddress
String

The address of the service.

Exceptions

endpointConfigurationName or remoteAddress is null.

The endpoint cannot be found or the endpoint contract is not valid.

Remarks

Use this constructor to determine the target endpoint information from the name of the endpoint in an application configuration file (The target value is located by finding the name attribute of the client <endpoint> element) and the specified address.

See also

Applies to

ClientBase<TChannel>(String, EndpointAddress)

Initializes a new instance of the ClientBase<TChannel> class using the specified target address and endpoint information.

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)

Parameters

endpointConfigurationName
String

The name of the endpoint in the application configuration file.

remoteAddress
EndpointAddress

The address of the service.

Exceptions

endpointConfigurationName or remoteAddress is null.

The endpoint cannot be found or the endpoint contract is not valid.

Remarks

Use this constructor to determine the target endpoint information from the name of the endpoint in an application configuration file (The target value is located by finding the name attribute of the client <endpoint> element) and the specified address.

Applies to

ClientBase<TChannel>(InstanceContext, String)

Initializes a new instance of the ClientBase<TChannel> class using the specified callback service and endpoint configuration information.

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)

Parameters

callbackInstance
InstanceContext

The callback object that the client uses to listen for messages from the connected service.

endpointConfigurationName
String

The name of the endpoint in the application configuration file.

Exceptions

The callback instance or endpointConfigurationName is null.

The endpoint cannot be found or the endpoint contract is not valid.

Remarks

Use this constructor to pass a service object that implements the callback contract for the target service and determine the target endpoint information from the client application configuration file. The target value is located by finding the name attribute of the client <endpoint> element.

Applies to

ClientBase<TChannel>(InstanceContext, String, EndpointAddress)

Initializes a new instance of the ClientBase<TChannel> class.

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)

Parameters

callbackInstance
InstanceContext

The callback object that the client uses to listen for messages from the connected service.

endpointConfigurationName
String

The name of the endpoint in the application configuration file.

remoteAddress
EndpointAddress

The address of the service.

Exceptions

The callback instance, endpointConfigurationName, or remoteAddress is null.

The endpoint cannot be found or the endpoint contract is not valid.

Remarks

Use this constructor to pass a service object that implements the callback contract for the target service and determine the target endpoint information from the name of the endpoint in an application configuration file (The target value is located by finding the name attribute of the client <endpoint> element) and the specified address.

See also

Applies to

ClientBase<TChannel>(Binding, EndpointAddress)

Source:
ClientBase.cs
Source:
ClientBase.cs

Initializes a new instance of the ClientBase<TChannel> class using the specified binding and target address.

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)

Parameters

binding
Binding

The binding with which to make calls to the service.

remoteAddress
EndpointAddress

The address of the service endpoint.

Exceptions

binding or remoteAddress is null.

Applies to

ClientBase<TChannel>(String)

Initializes a new instance of the ClientBase<TChannel> class using the configuration information specified in the application configuration file by 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)

Parameters

endpointConfigurationName
String

The name of the endpoint in the application configuration file.

Exceptions

The specified endpoint information is null.

The endpoint cannot be found or the endpoint contract is not valid.

Remarks

Use this constructor when there is more than one target endpoint in the application configuration file. This value is the name attribute of the client <endpoint> element.

Applies to

ClientBase<TChannel>(InstanceContext)

Initializes a new instance of the ClientBase<TChannel> class using the callbackInstance as the callback object in a duplex conversation.

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)

Parameters

callbackInstance
InstanceContext

The callback object that the client application uses to listen for messages from the connected service.

Exceptions

The callback instance is null.

Either there is no default endpoint information in the configuration file, more than one endpoint in the file, or no configuration file.

Examples

The following code example shows how to use this constructor with a SampleDuplexHelloClient class to pass a callback object that listens for messages from the service.

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

Remarks

Use this constructor when the service contract requires a callback service instance. The target endpoint is constructed from the type parameter and information in the application configuration file.

See also

Applies to

ClientBase<TChannel>(ServiceEndpoint)

Source:
ClientBase.cs
Source:
ClientBase.cs

Initializes a new instance of the ClientBase<TChannel> class using the specified 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)

Parameters

endpoint
ServiceEndpoint

The endpoint for a service that allows clients to find and communicate with the service.

Applies to

ClientBase<TChannel>(InstanceContext, ServiceEndpoint)

Initializes a new instance of the ClientBase<TChannel> class using the specified InstanceContext and ServiceEndpoint objects.

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)

Parameters

callbackInstance
InstanceContext

The callback object that the client application uses to listen for messages from the connected service.

endpoint
ServiceEndpoint

The endpoint for a service that allows clients to find and communicate with the service.

Applies to