HttpClientChannel クラス

定義

HTTP プロトコルを使用してメッセージを送信するリモート呼び出し用のクライアント チャネルを実装します。

public ref class HttpClientChannel : System::Runtime::Remoting::Channels::BaseChannelWithProperties, System::Runtime::Remoting::Channels::IChannelSender
public ref class HttpClientChannel : System::Runtime::Remoting::Channels::BaseChannelWithProperties, System::Runtime::Remoting::Channels::IChannelSender, System::Runtime::Remoting::Channels::ISecurableChannel
public class HttpClientChannel : System.Runtime.Remoting.Channels.BaseChannelWithProperties, System.Runtime.Remoting.Channels.IChannelSender
public class HttpClientChannel : System.Runtime.Remoting.Channels.BaseChannelWithProperties, System.Runtime.Remoting.Channels.IChannelSender, System.Runtime.Remoting.Channels.ISecurableChannel
type HttpClientChannel = class
    inherit BaseChannelWithProperties
    interface IChannelSender
    interface IChannel
type HttpClientChannel = class
    inherit BaseChannelWithProperties
    interface IChannelSender
    interface IChannel
    interface ISecurableChannel
Public Class HttpClientChannel
Inherits BaseChannelWithProperties
Implements IChannelSender
Public Class HttpClientChannel
Inherits BaseChannelWithProperties
Implements IChannelSender, ISecurableChannel
継承
実装

次のコード例は、 HttpClientChannel を使用してリモート処理サーバーとそのクライアントを設定する方法を示しています。 この例には、次の 3 つの部分が含まれています。

  • サーバー

  • クライアント

  • サーバーとクライアントによって使用されるリモート オブジェクト

次のコード例は、サーバーを示しています。

#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 = gcnew HttpServerChannel( 9090 );
   
   // Register the server channel.
   ChannelServices::RegisterChannel( serverChannel );
   
   // Expose an object for remote calls.
   RemotingConfiguration::RegisterWellKnownServiceType( RemoteObject::typeid, L"RemoteObject.rem", WellKnownObjectMode::Singleton );
   
   // Wait for the user prompt.
   Console::WriteLine( L"Press ENTER to exit the server." );
   Console::ReadLine();
   Console::WriteLine( L"The server is exiting." );
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;

public class Server
{
    public static void Main(string[] args)
    {
        // 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), "RemoteObject.rem",
            WellKnownObjectMode.Singleton);

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

次のコード例は、このサーバーのクライアントを示しています。

#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 = gcnew HttpClientChannel;

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

   // Register as client for remote object.
   WellKnownClientTypeEntry^ remoteType = gcnew WellKnownClientTypeEntry( RemoteObject::typeid,L"http://localhost:9090/RemoteObject.rem" );
   RemotingConfiguration::RegisterWellKnownClientType( remoteType );

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

   // Display the channel's properties using Keys and Item.
   for each(String^ key in clientChannel->Keys)
   {
       Console::WriteLine("clientChannel[{0}] = <{1}>", key, clientChannel[key]);
   }

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

   // Create an instance of the remote object.
   RemoteObject^ service = gcnew RemoteObject;
   
   // Invoke a method on the remote object.
   Console::WriteLine( L"The client is invoking the remote object." );
   Console::WriteLine( L"The remote object has been called {0} times.", service->GetCount() );
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;

public class Client
{
    public static void Main(string[] args)
    {
        // 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),
            "http://localhost:9090/RemoteObject.rem");
        RemotingConfiguration.RegisterWellKnownClientType(remoteType);

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

        // Display the channel's properties using Keys and Item.
        foreach(string key in clientChannel.Keys)
        {
            Console.WriteLine(
                "clientChannel[{0}] = <{1}>",
                key, clientChannel[key]);
        }

        // Parse the channel's URI.
        string objectUrl = "http://localhost:9090/RemoteObject.rem";
        string channelUri = clientChannel.Parse(objectUrl, out objectUri);
        Console.WriteLine("The object URL is {0}.", objectUrl);
        Console.WriteLine("The object URI is {0}.", objectUri);
        Console.WriteLine("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("The client is invoking the remote object.");
        Console.WriteLine("The remote object has been called {0} times.",
            service.GetCount());
    }
}

次のコード例は、サーバーとクライアントで使用されるリモート オブジェクトを示しています。

#using <System.dll>
using namespace System;
using namespace System::Runtime::Remoting;

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

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

};
using System;
using System.Runtime.Remoting;

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

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

注釈

Important

信頼されていないデータを使用してこのクラスからメソッドを呼び出すことは、セキュリティ上のリスクです。 このクラスのメソッドは、信頼できるデータでのみ呼び出します。 詳細については、「すべての入力を検証する」を参照してください。

チャネルは、リモート処理の境界を越えて (たとえば、コンピューターまたはアプリケーション ドメイン間で) メッセージを転送します。 HttpClientChannel クラスは、HTTP プロトコルを使用してメッセージを転送します。

チャネルは、リモート呼び出しを転送するために、.NET Framework リモート処理インフラストラクチャによって使用されます。 クライアントがリモート オブジェクトを呼び出すと、その呼び出しは、クライアント チャネルによって送信され、サーバー チャネルによって受信されるメッセージにシリアル化されます。 その後、逆シリアル化されて処理されます。 返された値はすべて、サーバー チャネルによって送信され、クライアント チャネルによって受信されます。

クライアント側でメッセージの追加処理を実行するには、HttpClientChannelによって処理されるすべてのメッセージが渡されるIClientChannelSinkProviderの実装を指定できます。

既定では、 HttpServerChannel は SOAP フォーマッタを使用してすべてのメッセージをシリアル化します。

HttpClientChannel オブジェクトには関連付けられた構成プロパティがあり、実行時に構成ファイル内で (静的RemotingConfiguration.Configure メソッドを呼び出すことによって) またはプログラムによって (HttpClientChannel コンストラクターにIDictionary コレクションを渡すことによって) 設定できます。

コンストラクター

名前 説明
HttpClientChannel()

HttpClientChannel クラスの新しいインスタンスを初期化します。

HttpClientChannel(IDictionary, IClientChannelSinkProvider)

指定した構成プロパティとシンクを使用して、 HttpClientChannel クラスの新しいインスタンスを初期化します。

HttpClientChannel(String, IClientChannelSinkProvider)

指定した名前とシンクを使用して、 HttpClientChannel クラスの新しいインスタンスを初期化します。

フィールド

名前 説明
SinksWithProperties

チャネル シンク スタック内の最上位チャネル シンクを示します。

(継承元 BaseChannelWithProperties)

プロパティ

名前 説明
ChannelName

現在のチャネルの名前を取得します。

ChannelPriority

現在のチャネルの優先順位を取得します。

Count

チャネル オブジェクトに関連付けられているプロパティの数を取得します。

(継承元 BaseChannelObjectWithProperties)
IsFixedSize

チャネル オブジェクトに入力できるプロパティの数が固定されているかどうかを示す値を取得します。

(継承元 BaseChannelObjectWithProperties)
IsReadOnly

チャネル オブジェクト内のプロパティのコレクションが読み取り専用かどうかを示す値を取得します。

(継承元 BaseChannelObjectWithProperties)
IsSecured

クライアント チャネルをセキュリティで保護するかどうかを取得または設定します。

IsSynchronized

チャネル オブジェクト プロパティのディクショナリが同期されているかどうかを示す値を取得します。

(継承元 BaseChannelObjectWithProperties)
Item[Object]

指定したチャネル プロパティを返します。

Keys

チャネル プロパティが関連付けられているキーの ICollection を取得します。

Properties

現在のチャネル オブジェクトに関連付けられているチャネル プロパティの IDictionary を取得します。

(継承元 BaseChannelWithProperties)
SyncRoot

BaseChannelObjectWithPropertiesへのアクセスを同期するために使用されるオブジェクトを取得します。

(継承元 BaseChannelObjectWithProperties)
Values

チャネル オブジェクトに関連付けられているプロパティの値の ICollection を取得します。

(継承元 BaseChannelObjectWithProperties)

メソッド

名前 説明
Add(Object, Object)

NotSupportedException をスローします。

(継承元 BaseChannelObjectWithProperties)
Clear()

NotSupportedException をスローします。

(継承元 BaseChannelObjectWithProperties)
Contains(Object)

チャネル オブジェクトに、指定したキーに関連付けられているプロパティが含まれているかどうかを示す値を返します。

(継承元 BaseChannelObjectWithProperties)
CopyTo(Array, Int32)

NotSupportedException をスローします。

(継承元 BaseChannelObjectWithProperties)
CreateMessageSink(String, Object, String)

指定した URL またはチャネル データ オブジェクトにメッセージを配信するチャネル メッセージ シンクを返します。

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetEnumerator()

チャネル オブジェクトに関連付けられているすべてのプロパティを列挙する IDictionaryEnumerator を返します。

(継承元 BaseChannelObjectWithProperties)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Objectの簡易コピーを作成します。

(継承元 Object)
Parse(String, String)

指定した URL からチャネル URI とリモートの既知のオブジェクト URI を抽出します。

Remove(Object)

NotSupportedException をスローします。

(継承元 BaseChannelObjectWithProperties)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

明示的なインターフェイスの実装

名前 説明
IEnumerable.GetEnumerator()

チャネル オブジェクトに関連付けられているすべてのプロパティを列挙する IEnumerator を返します。

(継承元 BaseChannelObjectWithProperties)

拡張メソッド

名前 説明
AsParallel(IEnumerable)

クエリの並列化を有効にします。

AsQueryable(IEnumerable)

IEnumerableIQueryableに変換します。

Cast<TResult>(IEnumerable)

IEnumerable の要素を指定した型にキャストします。

OfType<TResult>(IEnumerable)

指定した型に基づいて、IEnumerable の要素をフィルター処理します。

適用対象