This documentation is archived and is not being maintained.

WebChannelFactory<TChannel> Class

A class for accessing Windows Communication Foundation (WCF) Web services on a client.

Namespace:  System.ServiceModel.Web
Assembly:  System.ServiceModel.Web (in System.ServiceModel.Web.dll)

public class WebChannelFactory<TChannel> : ChannelFactory<TChannel>
where TChannel : class

Type Parameters


The type of channel to create.

This class is a special ChannelFactory that automatically adds the WebHttpBehavior to the endpoint if it is not already present. Furthermore, it adds a default WebHttpBinding to the endpoint if the binding is not explicitly configured and the address is an HTTP or HTTPS address.

If all the operations of the contract have no return value or have a return value of type Stream, then the WebChannelFactory<TChannel> configures the binding for the appropriate content type.

The following code shows how to use the WebChannelFactory<TChannel> class to call a WCF service.

Uri baseAddress = new Uri("http://localhost:8000");
WebServiceHost host = new WebServiceHost(typeof(Service), baseAddress);

    WebChannelFactory<IService> cf = new WebChannelFactory<IService>(baseAddress);
    IService channel = cf.CreateChannel();
    string s;

    Console.WriteLine("Calling EchoWithGet via HTTP GET: ");
    s = channel.EchoWithGet("Hello, world");
    Console.WriteLine("   Output: {0}", s);


    Console.WriteLine("Calling EchoWithPost via HTTP POST: ");
    s = channel.EchoWithPost("Hello, world");
    Console.WriteLine("   Output: {0}", s);

catch (CommunicationException ex)
    Console.WriteLine("An exception occurred: " + ex.Message);

For a full code example, see Basic Web Programming Model Sample.


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5