- PR -

.NET Remoting (CAO) でのスポンサー実装

1
投稿者投稿内容
ghornety
会議室デビュー日: 2005/08/03
投稿数: 6
投稿日時: 2005-09-21 12:15
過去ログ
http://www.atmarkit.co.jp/bbs/phpBB/viewtopic.php?topic=5662&forum=7
等を参考にスポンサー実装でエラー回避はできたのですが、登録したスポンサーが
何故か実行されません。

// クライアントのコード
public class Form1 : System.Windows.Forms.Form
{
〜省略〜
private void Form1_Load(object sender, System.EventArgs e)
{
ChannelServices.RegisterChannel(new TcpChannel(0));
RemotingConfiguration.RegisterActivatedClientType(
typeof(RemoteClass), "tcp://localhost:8000/MyApp");
remoteObject = new RemoteClass();
//リースのスポンサーを登録
ILease myLease = (ILease)RemotingServices.GetLifetimeService(remoteObject);
myLease.Register(new SponsorClass());
}
 〜省略〜
}
public class SponsorClass: MarshalByRefObject, ISponsor
{
public TimeSpan Renewal(ILease lease)
{
〜省略:この部分でリース延長時間をリターンしている〜
}
}

// サーバのコード
class Class1
{
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("サーバ起動...");
LifetimeServices.LeaseManagerPollTime = TimeSpan.FromSeconds(1);
LifetimeServices.LeaseTime = TimeSpan.FromSeconds(10);
LifetimeServices.RenewOnCallTime = TimeSpan.FromSeconds(3);
BinaryServerFormatterSinkProvider provider =
new BinaryServerFormatterSinkProvider();
provider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
IDictionary props = new Hashtable();
props["port"] = 8000;
ChannelServices.RegisterChannel(new TcpChannel(props, null, provider));
RemotingConfiguration.RegisterActivatedServiceType(typeof(RemoteClass));
RemotingConfiguration.ApplicationName = "MyApp";
Console.WriteLine("[Enter]キーでサーバ停止");
Console.ReadLine();
}
}

実際にはスポンサーRenewalが実行されないだけで問題なく動作します。
何か、ご存知の方がおられましたらよろしくお願い致します。
nanbu
大ベテラン
会議室デビュー日: 2004/08/19
投稿数: 178
投稿日時: 2005-09-21 23:25
南部です。

クライアントのTypeFilterLevelもFullにする必要があります。

コード:
BinaryServerFormatterSinkProvider provider = 
  new BinaryServerFormatterSinkProvider();
provider.TypeFilterLevel = TypeFilterLevel.Full;
IDictionary props = new Hashtable();
props["port"] = 0;
TcpChannel channel = new TcpChannel(props, null, provider);
ChannelServices.RegisterChannel(channel);
(略)

ghornety
会議室デビュー日: 2005/08/03
投稿数: 6
投稿日時: 2005-09-22 11:18
南部さん、ご丁寧にコードまでありがとうございます。

おかげさまで、リース延長が出来るようになりました。

「これからはじめる.NET Framework .NETリモーティング編」という本を参考に
SAOは比較的簡単に作る事ができたのですが、クライアント毎に値を保持したい為
CAO版の作成に着手したのですが、リース延長が出来なくて困っていました。

ありがとうございました。
1

スキルアップ/キャリアアップ(JOB@IT)