/// <summary> /// Set things in motion so your service can do its work. /// </summary> public void StartHosting(string tcpChannel, int tcpPort, string httpChannel, int httpPort, string ip) { try { #if !NETCORE _channel.RegisterTcpChannels(tcpChannel, ip, tcpPort); _channel.RegisterHttpChannels(httpChannel, ip, httpPort); Assembly remoting = Assembly.GetAssembly(typeof(System.Runtime.Remoting.RemotingConfiguration)); #endif //assign the BindToIP to cacheserver.clusterip if (_remoteableObject is CacheServer) { ((CacheServer)_remoteableObject).ClusterIP = ip; } #if !NETCORE RemotingServices.Marshal(_remoteableObject, _url); RemotingConfiguration.CustomErrorsMode = CustomErrorsModes.Off; #endif } catch (Exception) { throw; } }
/// <summary> /// Returns a running instance of CacheServer; does not start the service. /// If user specifies in the client application an ip address to server channels to bind to /// then this method creates the server channel bound to that ip. also the object uri then uses /// the ip address instead of server name. /// </summary> /// <returns></returns> public override ICacheServer ConnectCacheServer() { string objectUri = ""; string protocol; string ip = ""; try { if (_channel == null) { _channel = new RemotingChannels(); ip = ServiceConfiguration.BindToIP.ToString(); if (ip != null && ip.Length > 0) { if (_useTcp) { _channel.RegisterTcpChannels("NCC", ip, 0); } else { _channel.RegisterHttpChannels("NCC", ip, 0); } } else { if (_useTcp) { _channel.RegisterTcpChannels("NCC", 0); } else { _channel.RegisterHttpChannels("NCC", 0); } } } protocol = _useTcp ? @"tcp://" : @"http://"; if (ip != null && ip.Length > 0) { objectUri = protocol + ip + ":" + _port + @"/" + CacheHost.ApplicationName + @"/" + Alachisoft.NCache.Management.CacheServer.ObjectUri; } else { objectUri = protocol + _serverName + ":" + _port + @"/" + CacheHost.ApplicationName + @"/" + Alachisoft.NCache.Management.CacheServer.ObjectUri; } CacheServer server = (CacheServer) Activator.GetObject(typeof(CacheServer), objectUri, WellKnownObjectMode.Singleton); int ccount = server.Caches.Count; if (ccount > 0) { server = server; } return(server); } catch (SocketException socketException) { throw; } catch (ManagementException mexp) { throw; } catch (Exception e) { throw new ManagementException(e.Message, e); } }