.NET で VB6 ActiveX EXE をレプリケートしようとして、.NET リモート処理について理解を深めようとしています。
これまでのところ、すべてのクライアントが共有できるサーバー上でインスタンス化されたシングルトンがあります。
シングルトンはクライアントからのリクエストを受け入れてデータを検証し、検証済みのデータをイベントの形式で返します。これはうまく機能します。Singleton への参照を要求するクラスでは、イベントが発生します。つまり、データを送信し、検証済みのデータを受信します。
ただし、これにはインターフェイスが必要です。クライアントは WPF アプリケーション (サーバーも同様) でホストされており、クライアントがデータを受信したら、表示 (テキスト ボックス、リスト ボックスなど) を更新して、クライアントとシングルトンの間の通信を反映する必要があります。
ただし、メインフォームに実装されたイベントを追加して、クライアントがシングルトンからの応答を受信したときに呼び出すとすぐに、メインフォームにシリアル化属性がないことを訴える実行時エラーが発生します....
この簡潔さを保つために、次のようにプロセスを説明します
サーバーは次のコードで実行されます。
BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();
BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
//
IDictionary myDictionary = new Hashtable();
myDictionary["name"] = String.Format("PracticonChannel_{0}", Port);
myDictionary["typeFilterLevel"] = TypeFilterLevel.Full;
myDictionary["port"] = Port.ToString();
serverProvider.TypeFilterLevel = TypeFilterLevel.Full;
http = new HttpChannel(myDictionary, clientProvider, serverProvider);
// Register RemotingShared.SingletonObject as a
// Singleton Server-Activated type.
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(Practicon.RemotingShared.UploadObjectSingleton), // Server-activated type
"SingletonService", // objectUri
WellKnownObjectMode.Singleton // Singleton instancing mode
);
RemotingConfiguration.ApplicationName = " Upload Server";
RemotingConfiguration.RegisterActivatedServiceType(
typeof(Practicon.RemotingShared.UploadObjectSingleton));
クライアントは、次の方法でサーバーでアクティブ化されたシングルトンを取得します。
HttpChannel http1;
// Set the formatters of the messages for delivery.
BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();
BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
//
IDictionary myDictionary = new Hashtable();
myDictionary["name"] = String.Format("PracticonChannel_{0}", Port);
myDictionary["typeFilterLevel"] = TypeFilterLevel.Full;
myDictionary["port"] = port.ToString();
serverProvider.TypeFilterLevel = TypeFilterLevel.Full;
http1 = new HttpChannel(myDictionary, clientProvider, serverProvider);
ChannelServices.RegisterChannel(http1, false);
uploadObj= (UploadObjectSingleton)Activator.GetObject(
typeof(UploadObjectSingleton),
fullAddress);
//---------- Here's the problem...
uploadObj.ReplyEvent += new UploadObjectReplyEventHandler(OnUploadReply);
OnUploadReply は、さまざまなコントロールを更新する Form 実装イベントです。これが実行時に割り当てられると、メインフォームにシリアライゼーション属性がないため、シリアライゼーション例外が発生します。
これは私を夢中にさせています。シングルトン内で発生したイベントに応答してユーザーインターフェイスを更新する方法について、誰かが私に見せたり、説明したり、教えたり、説教したり、講義したりできますか?