This documentation is archived and is not being maintained.

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)

'Declaration
Public Class WebChannelFactory(Of TChannel As Class) _
	Inherits ChannelFactory(Of TChannel)
'Usage
Dim instance As WebChannelFactory(Of TChannel)

Type Parameters

TChannel

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

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

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

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

System.Object
  System.ServiceModel.Channels.CommunicationObject
    System.ServiceModel.ChannelFactory
      System.ServiceModel.ChannelFactory(Of TChannel)
        System.ServiceModel.Web.WebChannelFactory(Of TChannel)

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
Show: