This documentation is archived and is not being maintained.

HttpChannel Class

Implements a client channel for remote calls that uses the HTTP protocol to transmit messages.

Namespace:  System.Runtime.Remoting.Channels.Http
Assembly:  System.Runtime.Remoting (in System.Runtime.Remoting.dll)

'Declaration
Public Class HttpChannel _
	Inherits BaseChannelWithProperties _
	Implements IChannelReceiver, IChannelSender, IChannel, IChannelReceiverHook,  _
	ISecurableChannel
'Usage
Dim instance As HttpChannel

Channels transport messages across remoting boundaries (for example, between computers or application domains). The HttpChannel class transports messages using the HTTP protocol.

Channels are used by the .NET Framework remoting infrastructure to transport remote calls. When a client makes a call to a remote object, the call is serialized into a message that is sent by a client channel and received by a server channel. It is then deserialized and processed. Any returned values are transmitted by the server channel and received by the client channel.

A HttpChannel object has associated configuration properties that can be set at run time either in a configuration file (by invoking the static RemotingConfiguration.Configure method) or programmatically (by passing a IDictionary collection to the HttpChannel constructor). For a list of these configuration properties, see Channel and Formatter Configuration Properties.

The following code example shows how to use a HttpClientChannel to set up a remoting server and its client. The example contains three parts:

  • A server

  • A client

  • A remote object used by the server and the client

The following code example shows a server.

No code example is currently available or this language may not be supported.
#using <mscorlib.dll>
#using <System.dll>
#using <System.Runtime.Remoting.dll>
#using "common.dll"
using namespace System;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels;
using namespace System::Runtime::Remoting::Channels::Http;

void main()
{
    // Create the server channel.
    HttpServerChannel* serverChannel = new HttpServerChannel(9090);

    // Register the server channel.
    ChannelServices::RegisterChannel(serverChannel);

    // Expose an object for remote calls.
    RemotingConfiguration::RegisterWellKnownServiceType(
        __typeof(RemoteObject), S"RemoteObject.rem", 
        WellKnownObjectMode::Singleton);

    // Wait for the user prompt.
    Console::WriteLine(S"Press ENTER to exit the server.");
    Console::ReadLine();
    Console::WriteLine(S"The server is exiting.");
}

The following code example shows a client for this server.

No code example is currently available or this language may not be supported.
#using <mscorlib.dll>
#using <System.dll>
#using <System.Runtime.Remoting.dll>
#using "common.dll"
using namespace System;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels;
using namespace System::Runtime::Remoting::Channels::Http;

void main()
{
    // Create the channel.
    HttpClientChannel* clientChannel = new HttpClientChannel();

    // Register the channel.
    ChannelServices::RegisterChannel(clientChannel);

    // Register as client for remote object.
    WellKnownClientTypeEntry* remoteType = 
        new WellKnownClientTypeEntry(__typeof(RemoteObject), 
        S"http://localhost:9090/RemoteObject.rem");
    RemotingConfiguration::RegisterWellKnownClientType(remoteType);

    // Create a message sink.
    String* objectUri;
    System::Runtime::Remoting::Messaging::IMessageSink* messageSink = 
        clientChannel->CreateMessageSink(
        S"http://localhost:9090/RemoteObject.rem", 
        0, &objectUri);
    Console::WriteLine(
        S"The URI of the message sink is {0}.", 
        objectUri);
    if (messageSink != 0)
    {
        Console::WriteLine(S"The type of the message sink is {0}.", 
            messageSink->GetType());
    }

    // Display the channel's properties using Keys and Item.
    System::Collections::IEnumerator* myEnum = clientChannel->Keys->GetEnumerator();
    while (myEnum->MoveNext())
    {
        String* key = __try_cast<String*>(myEnum->Current);
        Console::WriteLine(
            S"clientChannel[{0}] = <{1}>", 
            key, clientChannel->Item[key]);
    }

    // Parse the channel's URI.
    String* objectUrl = S"http://localhost:9090/RemoteObject.rem";
    String* channelUri = clientChannel->Parse(objectUrl, &objectUri);
    Console::WriteLine(S"The object URL is {0}.", objectUrl);
    Console::WriteLine(S"The object URI is {0}.", objectUri);
    Console::WriteLine(S"The channel URI is {0}.", channelUri);

    // Create an instance of the remote object.
    RemoteObject* service = new RemoteObject(); 

    // Invoke a method on the remote object.
    Console::WriteLine(S"The client is invoking the remote object.");
    Console::WriteLine(S"The remote object has been called {0} times.", __box(service->GetCount()));

}

The following code example shows the remote object used by the server and the client.

No code example is currently available or this language may not be supported.
#using <mscorlib.dll>
using namespace System;
using namespace System::Runtime::Remoting;

// Remote object.
public __gc class RemoteObject : public MarshalByRefObject
{
private:
    static int callCount = 0;

public:
    int GetCount()
    {
        Console::WriteLine(S"GetCount was called.");
        callCount++;
        return(callCount);
    }

};

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 XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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, 3.0, 2.0, 1.1, 1.0
Show: