ChannelFactory<TChannel> Constructors

Definition

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

Overloads

ChannelFactory<TChannel>()

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

ChannelFactory<TChannel>(Binding)

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

ChannelFactory<TChannel>(ServiceEndpoint)

Initializes a new instance of the ChannelFactory<TChannel> class that produces channels with a specified endpoint.

ChannelFactory<TChannel>(String)

Initializes a new instance of the ChannelFactory<TChannel> class with a specified endpoint configuration name.

ChannelFactory<TChannel>(Type)

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

ChannelFactory<TChannel>(Binding, EndpointAddress)

Initializes a new instance of the ChannelFactory<TChannel> class with a specified binding and endpoint address.

ChannelFactory<TChannel>(Binding, String)

Initializes a new instance of the ChannelFactory<TChannel> class with a specified binding and remote address.

ChannelFactory<TChannel>(String, EndpointAddress)

Initializes a new instance of the ChannelFactory<TChannel> class associated with a specified name for the endpoint configuration and remote address.

ChannelFactory<TChannel>()

Source:
ChannelFactory.cs
Source:
ChannelFactory.cs

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

C#
public ChannelFactory();

Examples

This example shows how to create a new object of the ChannelFactory<TChannel> class with the IRequestChannel interface.

C#
EndpointAddress address = new EndpointAddress("http://localhost:8000/ChannelApp");
ChannelFactory<IRequestChannel> factory = new ChannelFactory<IRequestChannel>("MyEndpoint", address);

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

ChannelFactory<TChannel>(Binding)

Source:
ChannelFactory.cs
Source:
ChannelFactory.cs

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

C#
public ChannelFactory(System.ServiceModel.Channels.Binding binding);

Parameters

binding
Binding

The Binding specified for the channels produced by the factory.

Remarks

Use this constructor when you want to pass the binding information programmatically rather than using an application configuration file.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

ChannelFactory<TChannel>(ServiceEndpoint)

Source:
ChannelFactory.cs
Source:
ChannelFactory.cs

Initializes a new instance of the ChannelFactory<TChannel> class that produces channels with a specified endpoint.

C#
public ChannelFactory(System.ServiceModel.Description.ServiceEndpoint endpoint);

Parameters

endpoint
ServiceEndpoint

The ServiceEndpoint for the channels produced by the factory.

Exceptions

The endpoint is null.

Examples

C#
ContractDescription contract = new ContractDescription("MyContract");
EndpointAddress address = new EndpointAddress("http://localhost:8000/ChannelApp");
BasicHttpBinding binding = new BasicHttpBinding();
ServiceEndpoint endpoint = new ServiceEndpoint(contract, binding, address);

ChannelFactory<IRequestChannel> factory = new ChannelFactory<IRequestChannel>(endpoint);

Remarks

Use this constructor when you want to pass the service endpoint information programmatically rather than using an application configuration file.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

ChannelFactory<TChannel>(String)

Initializes a new instance of the ChannelFactory<TChannel> class with a specified endpoint configuration name.

C#
public ChannelFactory(string endpointConfigurationName);

Parameters

endpointConfigurationName
String

The configuration name used for the endpoint.

Exceptions

endpointConfigurationName is null.

Examples

C#
ChannelFactory<IRequestChannel> factory = new ChannelFactory<IRequestChannel>("MyEndpoint");

Remarks

Use this constructor when there is more than one target endpoint in the application configuration file.

Applies to

.NET Core 1.1 and other versions
Product Versions
.NET Core 1.0, Core 1.1
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
UWP 10.0

ChannelFactory<TChannel>(Type)

Source:
ChannelFactory.cs
Source:
ChannelFactory.cs

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

C#
protected ChannelFactory(Type channelType);

Parameters

channelType
Type

The Type of channel produced by the factory.

Exceptions

The channelType is null.

The channelType is a class or value type and is not an interface.

Remarks

Use this constructor when you want to pass the channel type information programmatically rather than using an application configuration file. The channelType parameter must be an interface.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET Core 1.0, Core 1.1, 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
UWP 10.0

ChannelFactory<TChannel>(Binding, EndpointAddress)

Source:
ChannelFactory.cs
Source:
ChannelFactory.cs

Initializes a new instance of the ChannelFactory<TChannel> class with a specified binding and endpoint address.

C#
public ChannelFactory(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress);

Parameters

binding
Binding

The Binding used to configure the endpoint.

remoteAddress
EndpointAddress

The EndpointAddress that provides the location of the service.

Exceptions

The binding is null.

Examples

C#
BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress address = new EndpointAddress("http://localhost:8000/ChannelApp");
ChannelFactory<IRequestChannel> factory = new ChannelFactory<IRequestChannel>(binding, address);

Remarks

Use this constructor when you want to pass the binding and address information programmatically rather than using an application configuration file.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET Core 1.0, Core 1.1, 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
UWP 10.0

ChannelFactory<TChannel>(Binding, String)

Source:
ChannelFactory.cs
Source:
ChannelFactory.cs

Initializes a new instance of the ChannelFactory<TChannel> class with a specified binding and remote address.

C#
public ChannelFactory(System.ServiceModel.Channels.Binding binding, string remoteAddress);

Parameters

binding
Binding

The Binding used to configure the endpoint.

remoteAddress
String

The address that provides the location of the service.

Exceptions

remoteAddress is null.

Examples

C#
BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress address = new EndpointAddress("http://localhost:8000/ChannelApp");
Uri via = new Uri("http://localhost:8000/Via");

ChannelFactory<IRequestChannel> factory =
    new ChannelFactory<IRequestChannel>(binding, "http://fsHost/fs/endp");

IRequestChannel channel = factory.CreateChannel(address, via);
channel.Open();
Message request = Message.CreateMessage(MessageVersion.Soap11, "hello");
Message reply = channel.Request(request);
Console.Out.WriteLine(reply.Headers.Action);
reply.Close();
channel.Close();
factory.Close();

Remarks

Use this constructor when you want to pass the information about the remote address information with a string rather than as a typed object.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

ChannelFactory<TChannel>(String, EndpointAddress)

Initializes a new instance of the ChannelFactory<TChannel> class associated with a specified name for the endpoint configuration and remote address.

C#
public ChannelFactory(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress);

Parameters

endpointConfigurationName
String

The configuration name used for the endpoint.

remoteAddress
EndpointAddress

The EndpointAddress that provides the location of the service.

Exceptions

endpointConfigurationName or remoteAddress is null.

Examples

C#
EndpointAddress address = new EndpointAddress("http://localhost:8000/ChannelApp");
ChannelFactory<IRequestChannel> factory = new ChannelFactory<IRequestChannel>("MyEndpoint", address);

Applies to

.NET Core 1.1 and other versions
Product Versions
.NET Core 1.0, Core 1.1
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
UWP 10.0