共用方式為


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 對象來設定遠端伺服器及其用戶端。 此範例包含三個部分:

  • 伺服器

  • 用戶端

  • 伺服器和用戶端所使用的遠端物件

下列程式代碼範例顯示伺服器。

#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 遠端基礎結構會使用通道來傳輸遠端呼叫。 當用戶端呼叫遠端物件時,呼叫會串行化為用戶端通道所傳送並由伺服器通道接收的訊息。 然後,它會還原串行化並處理。 任何傳回的值會由伺服器通道傳輸,並由用戶端通道接收。

若要在伺服器端執行其他訊息處理,您可以指定 傳遞所處理之所有訊息的 HttpServerChannelIServerChannelSinkProvider作。

接受 HttpServerChannel 以二進位或 SOAP 格式串行化的訊息。

HttpServerChannel物件具有相關聯的組態屬性,可藉由叫用靜態RemotingConfiguration.Configure方法) ,或透過程式設計 (方式將集合傳遞IDictionaryHttpServerChannel建構函式) ,在運行時間設定組態檔 (。 如需這些組態屬性的清單,請參閱 的檔。HttpServerChannel

建構函式

HttpServerChannel()

初始化 HttpServerChannel 類別的新執行個體。

HttpServerChannel(IDictionary, IServerChannelSinkProvider)

使用指定的通道屬性和接收,初始化 HttpServerChannel 類別的新執行個體。

HttpServerChannel(Int32)

初始化 HttpServerChannel 類別的新執行個體,這個執行個體包含指定的設計工具。

HttpServerChannel(String, Int32)

使用指定的名稱和會接聽指定的連接埠,初始化 HttpServerChannel 類別的新執行個體。

HttpServerChannel(String, Int32, IServerChannelSinkProvider)

在指定的連接埠上使用指定的名稱,初始化 HttpServerChannel 類別的新執行個體,其會接聽指定的連接埠,並使用指定的接收 (Sink)。

欄位

SinksWithProperties

指示通道接收堆疊中的頂端通道接收。

(繼承來源 BaseChannelWithProperties)

屬性

ChannelData

取得通道特定資料。

ChannelName

取得目前通道的名稱。

ChannelPriority

取得目前通道的優先權。

ChannelScheme

取得要連結的接聽程式類型 (例如,"http")。

ChannelSinkChain

取得目前通道正在使用的通道接收鏈結。

Count

取得與通道物件相關聯的屬性數目。

(繼承來源 BaseChannelObjectWithProperties)
IsFixedSize

取得值,指出可輸入到通道物件的屬性數目是否為固定的。

(繼承來源 BaseChannelObjectWithProperties)
IsReadOnly

取得值,指出通道物件中的屬性集合是否為唯讀。

(繼承來源 BaseChannelObjectWithProperties)
IsSynchronized

取得值,指出通道物件屬性的字典是否已經同步 (Synchronize)。

(繼承來源 BaseChannelObjectWithProperties)
Item[Object]

傳回指定的通道屬性。

Keys

取得與通道屬性相關聯之索引鍵的 ICollection

Properties

取得與目前通道物件相關聯之通道屬性的 IDictionary

(繼承來源 BaseChannelWithProperties)
SyncRoot

取得可用來對 BaseChannelObjectWithProperties 同步存取的物件。

(繼承來源 BaseChannelObjectWithProperties)
Values

取得與通道物件相關聯之屬性值的 ICollection

(繼承來源 BaseChannelObjectWithProperties)
WantsToListen

取得布林 (Boolean) 值,指出 IChannelReceiverHook 是否想要連結至外部接聽服務。

方法

Add(Object, Object)

擲回 NotSupportedException

(繼承來源 BaseChannelObjectWithProperties)
AddHookChannelUri(String)

加入 URI,通道攔截程序 (Hook) 必須在其上接聽。

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 的陣列,這 URI 裝載 (Host) 於目前 HttpChannel 上。

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)

IEnumerable 轉換成 IQueryable

適用於

另請參閱