//Initialize and connect to ATC Controller master. public AirportConverter() { try //Create connection to Server. { DuplexChannelFactory <IATCBizControllerMaster> factory; NetTcpBinding tcpBinding = new NetTcpBinding(); tcpBinding.MaxReceivedMessageSize = System.Int32.MaxValue; //Change max message & array size. tcpBinding.ReaderQuotas.MaxArrayLength = System.Int32.MaxValue; string sURL = "net.tcp://localhost:50001/ATCBiz"; factory = new DuplexChannelFactory <IATCBizControllerMaster>(new dummyCallback(), tcpBinding, sURL); IATCBizControllerMaster ATCBiz = factory.CreateChannel(); //Create connection. m_airports = ATCBiz.GetAirports(); } catch (FaultException ex) //SOAP fault. { System.Diagnostics.Debug.WriteLine(ex.Message); } catch (CommunicationException ex) //Communication error. { System.Diagnostics.Debug.WriteLine(ex.Message); } catch (TimeoutException ex) //Server likely has died or halted. { System.Diagnostics.Debug.WriteLine(ex.Message); } catch (Exception ex) //Generic exception for unknown problem. { System.Diagnostics.Debug.WriteLine("Exception type: " + ex.GetType()); System.Diagnostics.Debug.WriteLine("Exception message: " + ex.Message); } }
private Airport m_airport; //Airport owned by slave. //Constructor. Create connection to Server. public ATCBizControllerSlaveImpl() { try //To create connection to Server. { DuplexChannelFactory <IATCBizControllerMaster> factory; NetTcpBinding tcpBinding = new NetTcpBinding(); tcpBinding.MaxReceivedMessageSize = System.Int32.MaxValue; //Change max message & array size. tcpBinding.ReaderQuotas.MaxArrayLength = System.Int32.MaxValue; string sURL = "net.tcp://localhost:50001/ATCBiz"; factory = new DuplexChannelFactory <IATCBizControllerMaster>(this, tcpBinding, sURL); //Use this object for callback. m_ATCBiz = factory.CreateChannel(); //Create connection. m_airport = m_ATCBiz.RegisterSlave(); //Add Callback interface to masters list. if (m_airport != null) { m_airport.Routes = m_ATCBiz.GetRoutes(m_airport.AirportID); //Load routes from database. m_airport.Airplanes = m_ATCBiz.GetAirplanes(m_airport.AirportID); //Load airplanes from database. System.Console.WriteLine(m_airport.Name + " Airport ATC Running (ID: " + m_airport.AirportID + ")"); System.Console.ReadLine(); } else { System.Console.WriteLine("No airport returned"); //Program ends. } } catch (FaultException ex) //SOAP fault. { System.Console.WriteLine(ex.Message); } catch (CommunicationException ex) //Communication error. { System.Console.WriteLine("Can't connect to Server"); System.Console.WriteLine(ex.Message); } catch (TimeoutException ex) //Server likely has died or halted. { System.Console.WriteLine("Server timed out"); System.Console.WriteLine(ex.Message); } catch (Exception ex) //Generic exception for unknown problem. { System.Console.WriteLine("Exception type: " + ex.GetType()); System.Console.WriteLine("Exception message: " + ex.Message); } }
//Establish connection to business controller master and initialize list of airports. private void Window_Loaded(object sender, RoutedEventArgs e) { try //To create connection to Server. { DuplexChannelFactory <IATCBizControllerMaster> factory; NetTcpBinding tcpBinding = new NetTcpBinding(); tcpBinding.MaxReceivedMessageSize = System.Int32.MaxValue; //Change max message & array size. tcpBinding.ReaderQuotas.MaxArrayLength = System.Int32.MaxValue; string sURL = "net.tcp://localhost:50001/ATCBiz"; factory = new DuplexChannelFactory <IATCBizControllerMaster>(new dummyCallback(), tcpBinding, sURL); m_ATCBiz = factory.CreateChannel(); //Create connection. m_airports = m_ATCBiz.GetAirports(); lvwAirports.ItemsSource = m_airports; //Set listview of airports. } catch (FaultException ex) //SOAP fault. { System.Diagnostics.Debug.WriteLine(ex.Message); MessageBox.Show("Communication error, cannot continue at this time."); } catch (CommunicationException ex) //Communication error. { System.Diagnostics.Debug.WriteLine(ex.Message); MessageBox.Show("Can't connect to Server"); } catch (TimeoutException ex) //Server likely has died or halted. { System.Diagnostics.Debug.WriteLine(ex.Message); MessageBox.Show("Server timed out"); } catch (Exception ex) //Generic exception for unknown problem. { System.Diagnostics.Debug.WriteLine("Exception type: " + ex.GetType()); System.Diagnostics.Debug.WriteLine("Exception message: " + ex.Message); MessageBox.Show("Unexpected error, cannot continue at this time."); } }