服務總站的構建
總站在系統中充當著交易處理與協調的角色,每個用戶端需要請求之前必須要串連總站。在總站提供的服務中進行處理。而在具體編碼實現中,總站的地位與其他幾個伺服器的低位一致,在調用的時候只需要尋找相應總站的方法進行處理。總站功能結構如下:
namespace GlobalService{ /// <summary> /// 所有事務的執行都需要通過此類的ProcessTransaction()方法執行 /// 執行的必須條件為: /// *1.接受和設定表事務編號 String xid /// 2.接受和設定表Car的服務介面實現 ICarRemoteService m_carRemoteService; /// 3.接受和設定表Hotel的服務介面實現 IHotelRemoteService m_hotelRemoteService; /// 4.接受和設定表Flight的服務介面實現 IFlightRemoteService m_flightRemoteService; /// 5.接受和設定表Customer的服務介面實現 IcustomerRemoteService m_customerRemoteService; /// 6.接受和設定表Reservation的服務介面實現 IReservationRemoteService m_reservationRemoteService; /// *7.接受和設定表TransactionEntity的服務介面實現TransactionEntity m_TransactionEntity; /// </summary> public class GlobalControlServiceImpl : MarshalByRefObject, IGlobalControlService {
總站的參數列表
static void Main(string[] args) { #region 總站啟動 //TcpServerChannel chanGlobalService = new TcpServerChannel(9991); //ChannelServices.RegisterChannel(chanGlobalService, false); //RemotingConfiguration.RegisterWellKnownServiceType(typeof(GlobalControlServiceImpl), "Service", WellKnownObjectMode.Singleton); BinaryServerFormatterSinkProvider Serverprovider = new BinaryServerFormatterSinkProvider(); BinaryClientFormatterSinkProvider Clientprovider = new BinaryClientFormatterSinkProvider(); Serverprovider.TypeFilterLevel = TypeFilterLevel.Full; IDictionary props = new Hashtable(); props["Name"] = "RemoteTCP "; props["port"] = "9991"; TcpChannel chan = new TcpChannel(props, Clientprovider, Serverprovider); ChannelServices.RegisterChannel(chan, false); RemotingConfiguration.RegisterWellKnownServiceType (typeof(GlobalControlServiceImpl), "Service", WellKnownObjectMode.Singleton); RemotingConfiguration.RegisterWellKnownServiceType (typeof(QueueTransactionServiceImpl), "Queue", WellKnownObjectMode.Singleton); Console.WriteLine("總站啟動成功..."); Console.ReadLine(); #endregion #region 總站與CAR表相連 //TcpClientChannel chan = new TcpClientChannel(); //ChannelServices.RegisterChannel(chan, false); //ICarRemoteService carRemoteservice = (ICarRemoteService)Activator.GetObject(typeof(ICarRemoteService), "tcp://localhost:9999/Search", null); #endregion }
總站啟動代碼
由於總站需要操作每一個資料服務集合,所以在接受參數時需要同樣接受每一個資料服務集合的介面實作類別,保證能正常操作分布的資料集合。
圖.分伺服器和總伺服器以及用戶端的關係