/// <summary> /// Get zone status; connects to the end point address and reads the zone status. /// </summary> /// <param name="endPointAddress">Server end point address.</param> /// <param name="adr">Zone Address to get the status.</param> private static void GetZoneState(EndpointAddress endPointAddress, Address adr) { Console.WriteLine(">>> Setup M&C server ..."); ILog _log = LogManager.GetCurrentClassLogger(); IMonitorAndControl pipeProxy = null; IMonitorAndControlNotification serverCallback = new ServerCallback(); try { //var binding = new WSDualHttpBinding(WSDualHttpSecurityMode.None); var binding = new WSDualHttpBinding("WSDualHttpBinding_IMonitorAndControl"); int port = FindPort(); //binding.ClientBaseAddress = new Uri("http://" + machineIpOrName + ":" + port + "/"); //binding.ClientBaseAddress = new Uri("http://" + "192.168.1.115" + ":" + port + "/"); binding.ClientBaseAddress = new Uri("http://" + NetworkHelper.getHostName() + ":" + port + "/"); /*note the "DuplexChannelFactory". This is necessary for Callbacks. * A regular "ChannelFactory" won't work with callbacks.*/ DuplexChannelFactory <IMonitorAndControl> pipeFactory = new DuplexChannelFactory <IMonitorAndControl>( new InstanceContext(serverCallback), binding /*new NetTcpBinding()*/, endPointAddress /*new EndpointAddress("net.tcp://localhost:8000/ISubscribe")*/); try { Console.WriteLine(">>> creating channel to {0} with callback address {1}", endPointAddress.Uri.ToString(), binding.ClientBaseAddress.ToString()); //Open the channel to the server pipeProxy = pipeFactory.CreateChannel(); pipeProxy.Connect(); // Get zone status ZoneState state = pipeProxy.GetZoneState(adr); Console.WriteLine(">>> zone state: {0}", state.ToString()); } catch (Exception e) { Console.WriteLine("GetZoneState - Exception: {0}", e.Message); _log.Fatal(m => m("GetZoneState - Exception: {0}", e.Message)); } } catch (FaultException <ArgumentException> exc) { Console.WriteLine("GetZoneState - FaultException: {0}", exc); _log.Fatal(m => m("GetZoneState - FaultException: {0}", exc)); } catch (Exception exc) { Console.WriteLine("GetZoneState - Exception: {0}", exc); _log.Fatal(m => m("GetZoneState - Exception: {0}", exc)); } }
/// <summary> /// Reads the zone state from the service. /// </summary> /// <param name="zoneId">Address of the zone.</param> /// <returns>The read zone state.</returns> public ZoneState GetZoneState(Address zoneId) { _log.Trace(m => m(String.Format("M&C Proxy; GetZoneState(); Address: {0}", zoneId))); return(_mcServiceProxy.GetZoneState(zoneId)); }