SAOの定義
.NET RemotingのSAOをSpring.NETのコンテナに登録する方法を調べたのでメモ。
コンテナに登録
まず通常の方法で、SAOで公開したいオブジェクトを定義する。
<object name="hogeService" type="HogeHoge.Services.HogeService, HogeHoge"> </object>
このオブジェクトをSAOとして公開するために、「SaoServiceExporter」クラスを利用する。
<object name="hogeServiceSao" type="Spring.Remoting.SaoServiceExporter, Spring.Services"> <property name="Service" ref="hogeService" /> <property name="ServiceName" value="hogeService.rem" /> </object>
Serviceプロパティに公開するオブジェクトの参照を、
ServiceNameにこのRemotingオブジェクトにアクセスするための識別子を設定する。
これだけでは、もちろんサービスとして公開できないので、Remoting設定の構成ファイルを用意する。
以下、Remoting.config
<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.runtime.remoting> <application> <channels> <channel ref="http" port="9999" /> </channels> </application> </system.runtime.remoting> </configuration>
そしてこの定義ファイルを読み込むコードを記述する。
public static class StartApp { public static void Main() { // リモーティング設定 RemotingConfiguration.Configure("Remoting.config"); // コンテナのロード IApplicationContext context = new XmlApplicationContext("objects.xml"); // 待機 Console.ReadLine(); } }
クライアントからのアクセス
つづく・・・