服务总站的构建
总站在系统中充当着事务处理与协调的角色,每个客户端需要请求之前必须要连接总站。在总站提供的服务中进行处理。而在具体编码实现中,总站的地位与其他几个服务器的低位一致,在调用的时候只需要查找相应总站的方法进行处理。总站功能结构如下:
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
}
总站启动代码
由于总站需要操作每一个数据服务集合,所以在接受参数时需要同样接受每一个数据服务集合的接口实现类,保证能正常操作分布的数据集合。
图.分服务器和总服务器以及客户端的关系