HttpServerChannel クラス

定義

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

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

次のコード例は、 オブジェクトを HttpServerChannel 使用してリモート処理サーバーとそのクライアントを設定する方法を示しています。 この例には、次の 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;

int main()
{
   // Create the server channel.
   HttpServerChannel^ serverChannel = gcnew HttpServerChannel( 9090 );
   
   // Register the server channel.
   ChannelServices::RegisterChannel( serverChannel );
   
   // Display the channel's scheme.
   Console::WriteLine( L"The channel scheme is {0}.", serverChannel->ChannelScheme );
   
   // Display the channel's URI.
   Console::WriteLine( L"The channel URI is {0}.", serverChannel->GetChannelUri() );
   
   // Expose an object for remote calls.
   RemotingConfiguration::RegisterWellKnownServiceType(
      RemoteObject::typeid, L"RemoteObject.rem", WellKnownObjectMode::Singleton );
   
   // Get the channel's sink chain.
   IServerChannelSink^ sinkChain = serverChannel->ChannelSinkChain;
   Console::WriteLine( L"The type of the server channel's sink chain is {0}.", sinkChain->GetType() );
   
   // See if the channel wants to listen.
   bool wantsToListen = serverChannel->WantsToListen;
   Console::WriteLine( L"The value of WantsToListen is {0}.", wantsToListen );
   
   // Parse the channel's URI.
   array<String^>^ urls = serverChannel->GetUrlsForUri( L"RemoteObject.rem" );
   if ( urls->Length > 0 )
   {
      String^ objectUrl = urls[ 0 ];
      String^ objectUri;
      String^ channelUri = serverChannel->Parse( objectUrl,  objectUri );
      Console::WriteLine( L"The object URI is {0}.", objectUri );
      Console::WriteLine( L"The channel URI is {0}.", channelUri );
      Console::WriteLine( L"The object URL is {0}.", objectUrl );
   }

   
   // 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);

        // Display the channel's scheme.
        Console.WriteLine("The channel scheme is {0}.",
            serverChannel.ChannelScheme);

        // Display the channel's URI.
        Console.WriteLine("The channel URI is {0}.",
            serverChannel.GetChannelUri());

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

        // Get the channel's sink chain.
        IServerChannelSink sinkChain = serverChannel.ChannelSinkChain;
        Console.WriteLine(
            "The type of the server channel's sink chain is {0}.",
            sinkChain.GetType().ToString());

        // See if the channel wants to listen.
        bool wantsToListen = serverChannel.WantsToListen;
        Console.WriteLine(
            "The value of WantsToListen is {0}.",
            wantsToListen);

        // Parse the channel's URI.
        string[] urls = serverChannel.GetUrlsForUri("RemoteObject.rem");
        if (urls.Length > 0)
        {
            string objectUrl = urls[0];
            string objectUri;
            string channelUri =
                serverChannel.Parse(objectUrl, out objectUri);
            Console.WriteLine("The object URI is {0}.", objectUri);
            Console.WriteLine("The channel URI is {0}.", channelUri);
            Console.WriteLine("The object URL is {0}.", objectUrl);
        }

        // 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^ channel = gcnew HttpClientChannel;
   
   // Register the channel.
   ChannelServices::RegisterChannel( channel );
   
   // Register as client for remote object.
   WellKnownClientTypeEntry^ remoteType = gcnew WellKnownClientTypeEntry(
      RemoteObject::typeid,L"http://localhost:9090/RemoteObject.rem" );
   RemotingConfiguration::RegisterWellKnownClientType( remoteType );
   
   // 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 channel = new HttpClientChannel();

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

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

        // 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 namespace System;
using namespace System::Runtime::Remoting;

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

public:
   int GetCount()
   {
      callCount++;
      return (callCount);
   }

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

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

    public int GetCount()
    {
        callCount++;
        return(callCount);
    }
}

注釈

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

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

サーバー側でメッセージの追加処理を実行するには、 によって処理されるすべてのメッセージが渡される の IServerChannelSinkProvider 実装を HttpServerChannel 指定できます。

HttpServerChannel 、バイナリ形式または SOAP 形式でシリアル化されたメッセージを受け入れます。

HttpServerChannelオブジェクトには、実行時に設定できる構成プロパティが関連付けられています。このプロパティは、構成ファイル (静的RemotingConfiguration.Configureメソッドを呼び出すことによって) またはプログラムによって (コンストラクターにHttpServerChannelコレクションを渡IDictionaryすことによって) 設定できます。 これらの構成プロパティの一覧については、 のドキュメントを参照してください HttpServerChannel

コンストラクター

HttpServerChannel()

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

HttpServerChannel(IDictionary, IServerChannelSinkProvider)

チャネル プロパティとシンクを指定して、HttpServerChannel クラスの新しいインスタンスを初期化します。

HttpServerChannel(Int32)

指定したポートを待機する HttpServerChannel クラスの新しいインスタンスを初期化します。

HttpServerChannel(String, Int32)

指定した名前を持ち、指定したポートで待機する、HttpServerChannel クラスの新しいインスタンスを初期化します。

HttpServerChannel(String, Int32, IServerChannelSinkProvider)

指定したポートで指定した名前を持つ HttpServerChannel クラスの新しいインスタンスを初期化します。このインスタンスは、指定したポートで待機し、指定したシンクを使用します。

フィールド

SinksWithProperties

チャネル シンク スタックの一番上のチャネル シンクを示します。

(継承元 BaseChannelWithProperties)

プロパティ

ChannelData

チャネル固有のデータを取得します。

ChannelName

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

ChannelPriority

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

ChannelScheme

フックするリスナーの種類を取得します (たとえば "http")。

ChannelSinkChain

現在のチャネルが使用しているチャネル シンク チェインを取得します。

Count

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

(継承元 BaseChannelObjectWithProperties)
IsFixedSize

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

(継承元 BaseChannelObjectWithProperties)
IsReadOnly

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

(継承元 BaseChannelObjectWithProperties)
IsSynchronized

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

(継承元 BaseChannelObjectWithProperties)
Item[Object]

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

Keys

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

Properties

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

(継承元 BaseChannelWithProperties)
SyncRoot

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

(継承元 BaseChannelObjectWithProperties)
Values

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

(継承元 BaseChannelObjectWithProperties)
WantsToListen

IChannelReceiverHook を外部リスナー サービスにフックするかどうかを示すブール値を取得します。

メソッド

Add(Object, Object)

NotSupportedException をスローします。

(継承元 BaseChannelObjectWithProperties)
AddHookChannelUri(String)

チャネル フックが待機する URI を追加します。

Clear()

NotSupportedException をスローします。

(継承元 BaseChannelObjectWithProperties)
Contains(Object)

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

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

NotSupportedException をスローします。

(継承元 BaseChannelObjectWithProperties)
Equals(Object)

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

(継承元 Object)
GetChannelUri()

現在のチャネルの URI を返します。

GetEnumerator()

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

(継承元 BaseChannelObjectWithProperties)
GetHashCode()

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

(継承元 Object)
GetType()

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

(継承元 Object)
GetUrlsForUri(String)

指定した URI を持つオブジェクトのすべての URL のうち、現在の HttpChannel でホストされている URL の配列を返します。

MemberwiseClone()

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

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

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

Remove(Object)

NotSupportedException をスローします。

(継承元 BaseChannelObjectWithProperties)
StartListening(Object)

現在のチャネルに対して、要求の待機を開始するように指示します。

StopListening(Object)

現在のチャネルに対して、要求の待機を停止するように指示します。

ToString()

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

(継承元 Object)

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

IEnumerable.GetEnumerator()

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

(継承元 BaseChannelObjectWithProperties)

拡張メソッド

Cast<TResult>(IEnumerable)

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

OfType<TResult>(IEnumerable)

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

AsParallel(IEnumerable)

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

AsQueryable(IEnumerable)

IEnumerableIQueryable に変換します。

適用対象

こちらもご覧ください