public object Create(Type type) { logger.DebugFormat("Trying to find local reference to type {0}...", TypesHelper.GetFlatClassName(type)); object obj = ServiceLocationFactory.Do[ConfigCache].TryGet(type); if (obj != null) { logger.DebugFormat("Found it, returning..."); return(obj); } logger.DebugFormat("Creating remoting proxy to type {0}...", TypesHelper.GetFlatClassName(type)); Uri uriBase = ConfigCache.GetUriFromAddressBase(); string relativeUri = ConfigCache.GetEndpointKey(type); Uri uriFinal; if (Uri.TryCreate(uriBase, relativeUri, out uriFinal)) { logger.DebugFormat("Constructed URI: {0}...", uriFinal); ConfigCache.TryRegisterClientChannel(); obj = RemotingServices.Connect(type, uriFinal.AbsoluteUri); return(obj); } throw new InvalidOperationException("Invalid uri pair in configuration: '" + uriBase.AbsoluteUri + "' and '" + relativeUri + "'."); }
public void Host(object server, Type contract) { lock (this) { if (!(server is MarshalByRefObject)) { throw new ArgumentException("The server class must inherit from MarshalByRefObject"); } if (!started) { Start(); } services.Add(server); ServiceLocationFactory.Do[ConfigCache].Set(server, contract); string key = ConfigCache.GetEndpointKey(contract); if (!ConfigCache.LocalOnly) { logger.DebugFormat("Registering contract {0} at endpoint {1}...", contract.GetRealClassName(), key); RemotingServices.Marshal(server as MarshalByRefObject, key, contract); logger.InfoFormat("{0} hosted", key); foreach (string url in channel.GetUrlsForUri(key)) { logger.DebugFormat("* {0}.", url); } } else { logger.InfoFormat("{0} locally hosted", key); } } }