/// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); if (disposing) { if (_ManagerEPRef != null) { _ManagerEPRef.Dispose(); _ManagerEPRef = null; } if (_ServiceHost != null) { if (_ServiceHost.State == CommunicationState.Opened || _ServiceHost.State == CommunicationState.Opening) { _ServiceHost.Close(); } if (_ServiceHost.State == CommunicationState.Faulted) { _ServiceHost.Abort(); } } } }
private void GetManagerRef() { if (_ManagerEP != null) { _ManagerEPRef = GetRemoteManagerRef(_ManagerEP); _Manager = (IManager)_ManagerEPRef.Instance; } }
/// <summary> /// Gets the remote ref. /// </summary> /// <param name="remoteEP">The remote endpoint.</param> /// <param name="epType">WCF interface that the remote object implements. /// Only needed for WCF RemotingMechanisms. /// It can be null when RemotingMechanisem TcpBinary is used.</param> /// <param name="remoteObjectPrefix">The remote object prefix.</param> /// <returns></returns> public static EndPointReference GetRemoteRef(EndPoint remoteEP, Type epType, string remoteObjectPrefix) { EndPointReference epr = null; switch (remoteEP.RemotingMechanism) { case RemotingMechanism.TcpBinary: { #region TcpBinary epr = new EndPointReference(); string uri = "tcp://" + remoteEP.Host + ":" + remoteEP.Port + "/" + remoteObjectPrefix; epr.Instance = Activator.GetObject(typeof(GNode), uri); break; #endregion } case RemotingMechanism.WCFCustom: { #region WCFCustom System.ServiceModel.Channels.IChannelFactory <IExecutor> facExe = null; System.ServiceModel.Channels.IChannelFactory <IManager> facMan = null; System.ServiceModel.Channels.IChannelFactory <IOwner> facOwn = null; epr = new EndPointReference(); switch (epType.Name) { case "IExecutor": { facExe = new ChannelFactory <IExecutor>(remoteEP.ServiceConfigurationName); epr._fac = facExe; epr.Instance = facExe.CreateChannel(new EndpointAddress(remoteEP.FullAddress)); break; } case "IManager": { facMan = new ChannelFactory <IManager>(remoteEP.ServiceConfigurationName); epr._fac = facMan; epr.Instance = facMan.CreateChannel(new EndpointAddress(remoteEP.FullAddress)); break; } case "IOwner": { facOwn = new ChannelFactory <IOwner>(remoteEP.ServiceConfigurationName); epr._fac = facOwn; epr.Instance = facOwn.CreateChannel(new EndpointAddress(remoteEP.FullAddress)); break; } default: { throw new Exception("This type of WCF Service contract type is not supported"); } } break; #endregion } case RemotingMechanism.WCFTcp: { #region WCFTcp System.ServiceModel.Channels.IChannelFactory <IExecutor> facExe = null; System.ServiceModel.Channels.IChannelFactory <IManager> facMan = null; System.ServiceModel.Channels.IChannelFactory <IOwner> facOwn = null; remoteEP.Binding = WCFBinding.NetTcpBinding; epr = new EndPointReference(); switch (epType.Name) { case "IExecutor": { System.ServiceModel.NetTcpBinding tcpBin = (System.ServiceModel.NetTcpBinding)Utility.WCFUtils.GetWCFBinding(remoteEP); facExe = new ChannelFactory <IExecutor>(tcpBin); epr._fac = facExe; epr.Instance = facExe.CreateChannel(new EndpointAddress(remoteEP.FullAddress)); break; } case "IManager": { System.ServiceModel.NetTcpBinding tcpBin = (System.ServiceModel.NetTcpBinding)Utility.WCFUtils.GetWCFBinding(remoteEP); facMan = new ChannelFactory <IManager>(tcpBin); epr._fac = facMan; epr.Instance = facMan.CreateChannel(new EndpointAddress(remoteEP.FullAddress)); break; } case "IOwner": { System.ServiceModel.NetTcpBinding tcpBin = (System.ServiceModel.NetTcpBinding)Utility.WCFUtils.GetWCFBinding(remoteEP); facOwn = new ChannelFactory <IOwner>(tcpBin); epr._fac = facOwn; epr.Instance = facOwn.CreateChannel(new EndpointAddress(remoteEP.FullAddress)); break; } default: { throw new Exception("This type of WCF Service contract type is not supported"); } } break; #endregion } case RemotingMechanism.WCFHttp: { #region WCFHttp System.ServiceModel.Channels.IChannelFactory <IExecutor> facExe = null; System.ServiceModel.Channels.IChannelFactory <IManager> facMan = null; System.ServiceModel.Channels.IChannelFactory <IOwner> facOwn = null; epr = new EndPointReference(); remoteEP.Binding = WCFBinding.WSHttpBinding; switch (epType.Name) { case "IExecutor": { System.ServiceModel.WSHttpBinding wsHttpBin = (System.ServiceModel.WSHttpBinding)Utility.WCFUtils.GetWCFBinding(remoteEP); facExe = new ChannelFactory <IExecutor>(wsHttpBin); epr._fac = facExe; epr.Instance = facExe.CreateChannel(new EndpointAddress(remoteEP.FullAddress)); break; } case "IManager": { System.ServiceModel.WSHttpBinding wsHttpBin = (System.ServiceModel.WSHttpBinding)Utility.WCFUtils.GetWCFBinding(remoteEP); facMan = new ChannelFactory <IManager>(wsHttpBin); epr._fac = facMan; epr.Instance = facMan.CreateChannel(new EndpointAddress(remoteEP.FullAddress)); break; } case "IOwner": { System.ServiceModel.WSHttpBinding wsHttpBin = (System.ServiceModel.WSHttpBinding)Utility.WCFUtils.GetWCFBinding(remoteEP); facOwn = new ChannelFactory <IOwner>(wsHttpBin); epr._fac = facOwn; epr.Instance = facOwn.CreateChannel(new EndpointAddress(remoteEP.FullAddress)); break; } default: { throw new Exception("This type of WCF Service contract type is not supported"); } } break; #endregion } case RemotingMechanism.WCF: { #region WCF System.ServiceModel.Channels.IChannelFactory <IExecutor> facExe = null; System.ServiceModel.Channels.IChannelFactory <IManager> facMan = null; System.ServiceModel.Channels.IChannelFactory <IOwner> facOwn = null; epr = new EndPointReference(); switch (epType.Name) { case "IExecutor": { System.ServiceModel.Channels.Binding binding = Utility.WCFUtils.GetWCFBinding(remoteEP); facExe = new ChannelFactory <IExecutor>(binding); epr._fac = facExe; epr.Instance = facExe.CreateChannel(new EndpointAddress(remoteEP.FullAddress)); break; } case "IManager": { System.ServiceModel.Channels.Binding binding = Utility.WCFUtils.GetWCFBinding(remoteEP); facMan = new ChannelFactory <IManager>(binding); epr._fac = facMan; epr.Instance = facMan.CreateChannel(new EndpointAddress(remoteEP.FullAddress)); break; } case "IOwner": { System.ServiceModel.Channels.Binding binding = Utility.WCFUtils.GetWCFBinding(remoteEP); facOwn = new ChannelFactory <IOwner>(binding); epr._fac = facOwn; epr.Instance = facOwn.CreateChannel(new EndpointAddress(remoteEP.FullAddress)); break; } default: { throw new Exception("This type of WCF Service contract type is not supported"); } } break; #endregion } default: return(null); } return(epr); }