代码 12 :使用 Data Access Logic 进行 Remoting 调用 – 2 , Remoting 访问
class ** CustomerDal_ORM ** : ** MyDal **
{
// 请注意:这个 delegate 方法被限制为 private 访问权限
private ** ArrayList ** GetAllCustomers_Remoting_delegate()
{
** ArrayList ** al = null ;
** RemoteCustomer ** remote = ( ** RemoteCustomer ** ) ** Activator ** .GetObject(
typeof (RemotingClass. ** RemoteCustomer ** ),
** Helper ** .GetApplicationSetting("RemotingUrl"));
if (remote == null )
throw new ** Exception ** ("Could not locate server!");
else
{
al = remote.GetAllCustomers();
}
return al;
}
}
上面的两段代码应该不难理解,如果结合前面的 DAF ,我们就
可以画出这样一张调用示意图:
以上代码 11 , 12 (上图中的 1~6 步骤)仅仅是客户端行为,而
在服务器端,我们还不得不做这么两件事情:
(1) 建立一个 Host 程序(如果使用 Http+Soap 来模拟 WebServies ,由于该种 Remoting 行为可直接 Host 在 ASP.NET 下,故可省去本步骤),主要用于在指定端口注册服务(曾听朋友说起,网上也有人写过 Remoting Host Manager ,感兴趣的同志可以去 CodeProject 查查 J );
(2) 建立一个继承自 ** MarshalByRefObject ** 的服务类,该类将被步骤 1 中的 Host 程序用于注册操作;