ChannelFactory<TChannel>.CreateChannel Method

Definition

Creates a channel of a specified type to a specified endpoint address.

Overloads

CreateChannel(Binding, EndpointAddress, Uri)

Creates a channel of a specified type that is used to send messages to a service endpoint at a specified transport address that is configured with a specified binding.

CreateChannel(EndpointAddress, Uri)

Creates a channel that is used to send messages to a service at a specific endpoint address through a specified transport address.

CreateChannel(Binding, EndpointAddress)

Creates a channel of a specified type that is used to send messages to a service endpoint that is configured with a specified binding.

CreateChannel(EndpointAddress)

Creates a channel that is used to send messages to a service at a specific endpoint address.

CreateChannel()

Creates a channel of a specified type to a specified endpoint address.

CreateChannel(String)

Creates a channel that is used to send messages to a service whose endpoint is configured in a specified way.

Remarks

Creates a channel of type TChannel, the generic parameter for the class.

CreateChannel(Binding, EndpointAddress, Uri)

Source:
ChannelFactory.cs
Source:
ChannelFactory.cs

Creates a channel of a specified type that is used to send messages to a service endpoint at a specified transport address that is configured with a specified binding.

C#
public static TChannel CreateChannel(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress endpointAddress, Uri via);

Parameters

binding
Binding

The Binding used to configure the endpoint.

endpointAddress
EndpointAddress

The EndpointAddress that provides the location of the service.

via
Uri

The Uri that contains the transport address to which the channel sends messages.

Returns

TChannel

The TChannel of type IChannel created by the factory.

Exceptions

The ChannelFactory has duplex operations it does not support.

Examples

C#

 EndpointAddress address = new EndpointAddress("http://localhost:8000/ChannelApp");
 Uri uri = new Uri("http://localhost:8000/Via");

 IRequestChannel channel =
ChannelFactory<IRequestChannel>.CreateChannel(binding, address, uri);
 channel.Open();
C#
class Program : ChannelFactory<IService1Channel>
{
    static void Main(string[] args)
    {
        IService1Channel channel = CreateChannel("BasicHttpBinding_IService1");
        channel.Open();

        channel.Close();
    }
}

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

CreateChannel(EndpointAddress, Uri)

Source:
ChannelFactory.cs
Source:
ChannelFactory.cs
Source:
netstandard.cs

Creates a channel that is used to send messages to a service at a specific endpoint address through a specified transport address.

C#
public virtual TChannel CreateChannel(System.ServiceModel.EndpointAddress address, Uri via);

Parameters

address
EndpointAddress

The EndpointAddress that provides the location of the service.

via
Uri

The Uri that contains the transport address to which the channel sends messages.

Returns

TChannel

The TChannel of type IChannel created by the factory.

Implements

Exceptions

address is null.

The ChannelFactory has duplex operations it does not support.

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

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

Applies to

.NET 9 (package-provided) and other versions
Product Versions
.NET Core 1.0, Core 1.1, 8 (package-provided), 9 (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 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
UWP 10.0

CreateChannel(Binding, EndpointAddress)

Source:
ChannelFactory.cs
Source:
ChannelFactory.cs

Creates a channel of a specified type that is used to send messages to a service endpoint that is configured with a specified binding.

C#
public static TChannel CreateChannel(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress endpointAddress);

Parameters

binding
Binding

The Binding used to configure the endpoint.

endpointAddress
EndpointAddress

The EndpointAddress that provides the location of the service.

Returns

TChannel

The TChannel of type IChannel created by the factory.

Exceptions

The ChannelFactory has duplex operations it does not support.

Examples

C#

       EndpointAddress address = new EndpointAddress("http://localhost:8000/ChannelApp");
       IRequestChannel channel = ChannelFactory<IRequestChannel>.CreateChannel(binding, address);
       channel.Open();

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

CreateChannel(EndpointAddress)

Source:
ChannelFactory.cs
Source:
ChannelFactory.cs
Source:
netstandard.cs

Creates a channel that is used to send messages to a service at a specific endpoint address.

C#
public TChannel CreateChannel(System.ServiceModel.EndpointAddress address);

Parameters

address
EndpointAddress

The EndpointAddress that provides the location of the service.

Returns

TChannel

The TChannel of type IChannel created by the factory.

Implements

Exceptions

address is null.

Examples

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

Applies to

.NET 9 (package-provided) and other versions
Product Versions
.NET Core 1.0, Core 1.1, 8 (package-provided), 9 (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 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
UWP 10.0

CreateChannel()

Source:
ChannelFactory.cs
Source:
ChannelFactory.cs
Source:
netstandard.cs

Creates a channel of a specified type to a specified endpoint address.

C#
public TChannel CreateChannel();

Returns

TChannel

The TChannel of type IChannel created by the factory.

Examples

C#
IChannelFactory<IRequestChannel> factory = binding.BuildChannelFactory<IRequestChannel>(bindingParams);
factory.Open();
EndpointAddress address = new EndpointAddress("http://localhost:8000/ChannelApp");
IRequestChannel channel = factory.CreateChannel(address);
channel.Open();

Remarks

Creates a channel of type TChannel, the generic parameter for the class.

Applies to

.NET 9 (package-provided) and other versions
Product Versions
.NET Core 1.0, Core 1.1, 8 (package-provided), 9 (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 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
UWP 10.0

CreateChannel(String)

Creates a channel that is used to send messages to a service whose endpoint is configured in a specified way.

C#
protected static TChannel CreateChannel(string endpointConfigurationName);

Parameters

endpointConfigurationName
String

The name of the endpoint configuration used for the service.

Returns

TChannel

The TChannel of type IChannel created by the factory.

Exceptions

The ChannelFactory has duplex operations it does not support.

Examples

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

    ChannelFactory<IRequestChannel> factory =
        new ChannelFactory<IRequestChannel>(binding, address);

    IRequestChannel channel = factory.CreateChannel();
    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();
}

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