.NET Framework Class Library
WebChannelFactory<(Of <(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)
Syntax

Visual Basic (Declaration)
Public Class WebChannelFactory(Of TChannel As Class) _
    Inherits ChannelFactory(Of TChannel)
Visual Basic (Usage)
Dim instance As WebChannelFactory(Of TChannel)
C#
public class WebChannelFactory<TChannel> : ChannelFactory<TChannel>
where TChannel : class
Visual C++
generic<typename TChannel>
where TChannel : ref class
public ref class WebChannelFactory : public ChannelFactory<TChannel>
JScript
JScript does not support generic types or methods.

Type Parameters

TChannel

The type of channel to create.

Remarks

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<(Of <(TChannel>)>) configures the binding for the appropriate content type.

Examples

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

Visual Basic
Dim baseAddress As New Uri("http://localhost:8000")
Dim host As New WebServiceHost(GetType(Service), baseAddress)
Try
    host.Open()

    Dim cf As New WebChannelFactory(Of IService)(baseAddress)
    Dim channel As IService = cf.CreateChannel()
    Dim s As String

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

    Console.WriteLine("")

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

    Console.WriteLine("")

Catch ex As CommunicationException
    Console.WriteLine("An exception occurred: " + ex.Message)
End Try
C#
Uri baseAddress = new Uri("http://localhost:8000");
WebServiceHost host = new WebServiceHost(typeof(Service), baseAddress);
try
{
    host.Open();

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

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

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

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

Inheritance Hierarchy

System..::.Object
  System.ServiceModel.Channels..::.CommunicationObject
    System.ServiceModel..::.ChannelFactory
      System.ServiceModel..::.ChannelFactory<(Of <(TChannel>)>)
        System.ServiceModel.Web..::.WebChannelFactory<(Of <(TChannel>)>)
Thread Safety

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

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.
Version Information

.NET Framework

Supported in: 3.5
See Also

Reference

Tags :


Page view tracker