/// <summary> /// ConnectToDB /// connects to the data tier object /// </summary> public void ConnectToDB() { ChannelFactory <IDGDataController> channelFactory; NetTcpBinding tcpBinding = new NetTcpBinding(); string url = "net.tcp://localhost:50001/DGData"; try { // incease default message size quota tcpBinding.MaxReceivedMessageSize = System.Int32.MaxValue; tcpBinding.ReaderQuotas.MaxArrayLength = System.Int32.MaxValue; // bind channel to url channelFactory = new ChannelFactory <IDGDataController>(tcpBinding, url); // bind url to channel factory m_database = channelFactory.CreateChannel(); // create database on remote server } catch (ArgumentNullException e1) { Console.WriteLine("\nError: Binding URL to ChannelFactory\n" + e1.Message); CloseServer(1); } catch (CommunicationException e2) { Console.WriteLine("\nError: Communicating with Data Server \n" + e2.Message); CloseServer(1); } catch (InvalidOperationException e3) { Console.WriteLine("\nError: Modifying TcpBinding Message Quota\n" + e3.Message); CloseServer(1); } }
public DGBizControllerImpl() { //Biz server connects to server ChannelFactory <IDGDataController> DGData; NetTcpBinding tcpBinding = new NetTcpBinding(); //release the limitation of the size of message which can be sent tcpBinding.MaxReceivedMessageSize = System.Int32.MaxValue; tcpBinding.ReaderQuotas.MaxArrayLength = System.Int32.MaxValue; try { DGData = new ChannelFactory <IDGDataController>(tcpBinding, "net.tcp://localhost:50001/DGData"); m_DGData = DGData.CreateChannel(); userInfo = m_DGData.GetUserInfo(); } catch (CommunicationObjectFaultedException ex) { Console.WriteLine(ex.Message); } catch (Exception e) { Console.WriteLine("From DGBizControllerImpl.cs > DGBizControllerImpl\n" + e.Message); } inituserState(); clients = new Dictionary <String, IDGBizControllerCallback>(); lastEnterServer = new Dictionary <String, String>(); numberOfClientInServer = new Dictionary <string, int>(); serverList = new Dictionary <string, string>(); numberOfClientInServer.Add("Server1", 0); numberOfClientInServer.Add("Server2", 0); numberOfClientInServer.Add("Server3", 0); serverList.Add("Server1", "net.tcp://localhost:50003/DGServer1"); serverList.Add("Server2", "net.tcp://localhost:50004/DGServer2"); locker = new object(); startCount(); Console.WriteLine("Biz Server Started"); }
public DGSerControllerImpl() { ChannelFactory <IDGDataController> DGData; NetTcpBinding tcpBinding = new NetTcpBinding(); //release the limitation of the size of message which can be sent tcpBinding.MaxReceivedMessageSize = System.Int32.MaxValue; tcpBinding.ReaderQuotas.MaxArrayLength = System.Int32.MaxValue; try { //connect to Data Tier DGData = new ChannelFactory <IDGDataController>(tcpBinding, "net.tcp://localhost:50001/DGData"); m_DGData = DGData.CreateChannel(); } catch (CommunicationObjectFaultedException ex) { Console.WriteLine(ex.Message); } catch (Exception e) { Console.WriteLine("From DGSerControllerImpl.cs > DGSerControllerImpl\n" + e.Message); } calculation = new Calculation(); heroInfoList = new List <String>(); heroNameList = new List <String>(); try { heroInfo = m_DGData.GetHeroInfo(); bossInfo = m_DGData.GetBossInfo(); buildHeroInfoList(); initServer(); } catch (Exception e) { Console.WriteLine("From DGSerControllerImpl.cs > DGSerControllerImpl\n" + e.Message); } Console.WriteLine("Server1 Object Created"); }