實戰 .Net 資料訪問層 - 14
來源:互聯網
上載者:User
訪問|資料 代碼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程式用於註冊操作;
下一段:http://www.csdn.net/develop/Read_Article.asp?id=27558