HttpServerChannel Kelas
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Menerapkan saluran server untuk panggilan jarak jauh yang menggunakan protokol HTTP untuk mengirimkan pesan.
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
- Warisan
- Penerapan
Contoh
Contoh kode berikut menunjukkan cara menggunakan HttpServerChannel objek untuk menyiapkan server jarak jauh dan kliennya. Contohnya berisi tiga bagian:
Server
Klien
Objek jarak jauh yang digunakan oleh server dan klien
Contoh kode berikut menunjukkan server.
#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.");
}
}
Contoh kode berikut menunjukkan klien untuk server ini.
#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());
}
}
Contoh kode berikut menunjukkan objek jarak jauh yang digunakan oleh server dan klien.
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);
}
}
Keterangan
Saluran mengangkut pesan di seluruh batas jarak jauh (misalnya, antara komputer pada domain aplikasi). Kelas HttpServerChannel mengangkut pesan menggunakan protokol HTTP.
Saluran digunakan oleh infrastruktur jarak jauh .NET Framework untuk mengangkut panggilan jarak jauh. Ketika klien melakukan panggilan ke objek jarak jauh, panggilan diserialisasikan ke dalam pesan yang dikirim oleh saluran klien dan diterima oleh saluran server. Kemudian dideserialisasi dan diproses. Setiap nilai yang dikembalikan ditransmisikan oleh saluran server dan diterima oleh saluran klien.
Untuk melakukan pemrosesan pesan tambahan di sisi server, Anda dapat menentukan implementasi IServerChannelSinkProvider di mana semua pesan yang diproses oleh HttpServerChannel diteruskan.
HttpServerChannel menerima pesan yang diserialisasikan dalam format biner atau SOAP.
Objek HttpServerChannel memiliki properti konfigurasi terkait yang dapat diatur pada durasi baik dalam file konfigurasi (dengan memanggil metode statis RemotingConfiguration.Configure ) atau secara terprogram (dengan meneruskan IDictionary koleksi ke HttpServerChannel konstruktor). Untuk daftar properti konfigurasi ini, lihat dokumentasi untuk HttpServerChannel.
Konstruktor
HttpServerChannel() |
Menginisialisasi instans baru kelas HttpServerChannel. |
HttpServerChannel(IDictionary, IServerChannelSinkProvider) |
Menginisialisasi instans HttpServerChannel baru kelas dengan properti saluran dan sink yang ditentukan. |
HttpServerChannel(Int32) |
Menginisialisasi instans HttpServerChannel baru kelas yang mendengarkan pada port yang ditentukan. |
HttpServerChannel(String, Int32) |
Menginisialisasi instans HttpServerChannel baru kelas dengan nama yang diberikan dan yang mendengarkan pada port yang ditentukan. |
HttpServerChannel(String, Int32, IServerChannelSinkProvider) |
Menginisialisasi instans HttpServerChannel baru kelas di port yang ditentukan dengan nama yang diberikan, yang mendengarkan pada port yang ditentukan, dan menggunakan sink yang ditentukan. |
Bidang
SinksWithProperties |
Menunjukkan sink saluran atas di tumpukan sink saluran. (Diperoleh dari BaseChannelWithProperties) |
Properti
ChannelData |
Mendapatkan data khusus saluran. |
ChannelName |
Mendapatkan nama saluran saat ini. |
ChannelPriority |
Mendapatkan prioritas saluran saat ini. |
ChannelScheme |
Mendapatkan jenis pendengar untuk dikaitkan (misalnya, "http"). |
ChannelSinkChain |
Mendapatkan rantai sink saluran yang digunakan saluran saat ini. |
Count |
Mendapatkan jumlah properti yang terkait dengan objek saluran. (Diperoleh dari BaseChannelObjectWithProperties) |
IsFixedSize |
Mendapatkan nilai yang menunjukkan apakah jumlah properti yang dapat dimasukkan ke dalam objek saluran diperbaiki. (Diperoleh dari BaseChannelObjectWithProperties) |
IsReadOnly |
Mendapatkan nilai yang menunjukkan apakah kumpulan properti di objek saluran bersifat baca-saja. (Diperoleh dari BaseChannelObjectWithProperties) |
IsSynchronized |
Mendapatkan nilai yang menunjukkan apakah kamus properti objek saluran disinkronkan. (Diperoleh dari BaseChannelObjectWithProperties) |
Item[Object] |
Mengembalikan properti saluran yang ditentukan. |
Keys |
Mendapatkan kunci yang ICollection terkait dengan properti saluran. |
Properties |
Mendapatkan properti saluran yang IDictionary terkait dengan objek saluran saat ini. (Diperoleh dari BaseChannelWithProperties) |
SyncRoot |
Mendapatkan objek yang digunakan untuk menyinkronkan akses ke BaseChannelObjectWithProperties. (Diperoleh dari BaseChannelObjectWithProperties) |
Values |
ICollection Mendapatkan nilai properti yang terkait dengan objek saluran. (Diperoleh dari BaseChannelObjectWithProperties) |
WantsToListen |
Mendapatkan nilai Boolean yang menunjukkan apakah IChannelReceiverHook ingin dikaitkan dengan layanan pendengar luar. |
Metode
Add(Object, Object) |
Melempar .NotSupportedException (Diperoleh dari BaseChannelObjectWithProperties) |
AddHookChannelUri(String) |
Menambahkan URI tempat hook saluran harus mendengarkan. |
Clear() |
Melempar .NotSupportedException (Diperoleh dari BaseChannelObjectWithProperties) |
Contains(Object) |
Mengembalikan nilai yang menunjukkan apakah objek saluran berisi properti yang terkait dengan kunci yang ditentukan. (Diperoleh dari BaseChannelObjectWithProperties) |
CopyTo(Array, Int32) |
Melempar .NotSupportedException (Diperoleh dari BaseChannelObjectWithProperties) |
Equals(Object) |
Menentukan apakah objek yang ditentukan sama dengan objek saat ini. (Diperoleh dari Object) |
GetChannelUri() |
Mengembalikan URI saluran saat ini. |
GetEnumerator() |
Mengembalikan yang IDictionaryEnumerator menghitung semua properti yang terkait dengan objek saluran. (Diperoleh dari BaseChannelObjectWithProperties) |
GetHashCode() |
Berfungsi sebagai fungsi hash default. (Diperoleh dari Object) |
GetType() |
Mendapatkan instans Type saat ini. (Diperoleh dari Object) |
GetUrlsForUri(String) |
Mengembalikan array semua URL untuk objek dengan URI yang ditentukan, yang dihosting pada saat ini HttpChannel. |
MemberwiseClone() |
Membuat salinan dangkal dari yang saat ini Object. (Diperoleh dari Object) |
Parse(String, String) |
Mengekstrak URI saluran dan URI objek terkenal jarak jauh dari URL yang ditentukan. |
Remove(Object) |
Melempar .NotSupportedException (Diperoleh dari BaseChannelObjectWithProperties) |
StartListening(Object) |
Menginstruksikan saluran saat ini untuk mulai mendengarkan permintaan. |
StopListening(Object) |
Menginstruksikan saluran saat ini untuk berhenti mendengarkan permintaan. |
ToString() |
Mengembalikan string yang mewakili objek saat ini. (Diperoleh dari Object) |
Implementasi Antarmuka Eksplisit
IEnumerable.GetEnumerator() |
Mengembalikan yang IEnumerator menghitung semua properti yang terkait dengan objek saluran. (Diperoleh dari BaseChannelObjectWithProperties) |
Metode Ekstensi
Cast<TResult>(IEnumerable) |
Mentransmisikan elemen dari IEnumerable ke jenis yang ditentukan. |
OfType<TResult>(IEnumerable) |
Memfilter elemen berdasarkan IEnumerable jenis tertentu. |
AsParallel(IEnumerable) |
Mengaktifkan paralelisasi kueri. |
AsQueryable(IEnumerable) |
Mengonversi menjadi IEnumerableIQueryable. |