using System; using System.Collections; using System.Reflection; using System.Runtime.InteropServices; using System.Runtime.Remoting.Contexts; using System.Runtime.Remoting.Messaging; namespace System.Runtime.Remoting.Channels { /// Provides static methods to aid with remoting channel registration, resolution, and URL discovery. This class cannot be inherited. // Token: 0x02000395 RID: 917 [ComVisible(true)] public sealed class ChannelServices { // Token: 0x0600255C RID: 9564 RVA: 0x0007B94C File Offset: 0x00079B4C private ChannelServices() { } // Token: 0x170006F5 RID: 1781 // (get) Token: 0x0600255E RID: 9566 RVA: 0x0007B9A4 File Offset: 0x00079BA4 internal static CrossContextChannel CrossContextChannel { get { return ChannelServices._crossContextSink; } } // Token: 0x0600255F RID: 9567 RVA: 0x0007B9AC File Offset: 0x00079BAC internal static IMessageSink CreateClientChannelSinkChain(string url, object remoteChannelData, out string objectUri) { object[] array = (object[])remoteChannelData; object syncRoot = ChannelServices.registeredChannels.SyncRoot; lock (syncRoot) { foreach (object obj in ChannelServices.registeredChannels) { IChannel channel = (IChannel)obj; IChannelSender channelSender = channel as IChannelSender; if (channelSender != null) { IMessageSink messageSink = ChannelServices.CreateClientChannelSinkChain(channelSender, url, array, out objectUri); if (messageSink != null) { return messageSink; } } } RemotingConfiguration.LoadDefaultDelayedChannels(); foreach (object obj2 in ChannelServices.delayedClientChannels) { IChannelSender channelSender2 = (IChannelSender)obj2; IMessageSink messageSink2 = ChannelServices.CreateClientChannelSinkChain(channelSender2, url, array, out objectUri); if (messageSink2 != null) { ChannelServices.delayedClientChannels.Remove(channelSender2); ChannelServices.RegisterChannel(channelSender2); return messageSink2; } } } objectUri = null; return null; } // Token: 0x06002560 RID: 9568 RVA: 0x0007BB1C File Offset: 0x00079D1C internal static IMessageSink CreateClientChannelSinkChain(IChannelSender sender, string url, object[] channelDataArray, out string objectUri) { objectUri = null; if (channelDataArray == null) { return sender.CreateMessageSink(url, null, out objectUri); } foreach (object obj in channelDataArray) { IMessageSink messageSink; if (obj is IChannelDataStore) { messageSink = sender.CreateMessageSink(null, obj, out objectUri); } else { messageSink = sender.CreateMessageSink(url, obj, out objectUri); } if (messageSink != null) { return messageSink; } } return null; } /// Gets a list of currently registered channels. /// An array of all the currently registered channels. /// The immediate caller does not have infrastructure permission. /// /// /// // Token: 0x170006F6 RID: 1782 // (get) Token: 0x06002561 RID: 9569 RVA: 0x0007BB84 File Offset: 0x00079D84 public static IChannel[] RegisteredChannels { get { object syncRoot = ChannelServices.registeredChannels.SyncRoot; IChannel[] array; lock (syncRoot) { ArrayList arrayList = new ArrayList(); for (int i = 0; i < ChannelServices.registeredChannels.Count; i++) { IChannel channel = (IChannel)ChannelServices.registeredChannels[i]; if (!(channel is CrossAppDomainChannel)) { arrayList.Add(channel); } } array = (IChannel[])arrayList.ToArray(typeof(IChannel)); } return array; } } /// Creates a channel sink chain for the specified channel. /// A new channel sink chain for the specified channel. /// The first provider in the chain of sink providers that will create the channel sink chain. /// The for which to create the channel sink chain. /// The immediate caller does not have infrastructure permission. /// /// /// // Token: 0x06002562 RID: 9570 RVA: 0x0007BC34 File Offset: 0x00079E34 public static IServerChannelSink CreateServerChannelSinkChain(IServerChannelSinkProvider provider, IChannelReceiver channel) { IServerChannelSinkProvider serverChannelSinkProvider = provider; while (serverChannelSinkProvider.Next != null) { serverChannelSinkProvider = serverChannelSinkProvider.Next; } serverChannelSinkProvider.Next = new ServerDispatchSinkProvider(); return provider.CreateSink(channel); } /// Dispatches incoming remote calls. /// A that gives the status of the server message processing. /// The stack of server channel sinks that the message already traversed. /// The message to dispatch. /// When this method returns, contains a that holds the reply from the server to the message that is contained in the parameter. This parameter is passed uninitialized. /// The parameter is null. /// The immediate caller does not have infrastructure permission. /// /// /// /// // Token: 0x06002563 RID: 9571 RVA: 0x0007BC6C File Offset: 0x00079E6C public static ServerProcessing DispatchMessage(IServerChannelSinkStack sinkStack, IMessage msg, out IMessage replyMsg) { if (msg == null) { throw new ArgumentNullException("msg"); } replyMsg = ChannelServices.SyncDispatchMessage(msg); if (RemotingServices.IsOneWay(((IMethodMessage)msg).MethodBase)) { return ServerProcessing.OneWay; } return ServerProcessing.Complete; } /// Returns a registered channel with the specified name. /// An interface to a registered channel, or null if the channel is not registered. /// The channel name. /// The immediate caller does not have infrastructure permission. /// /// /// // Token: 0x06002564 RID: 9572 RVA: 0x0007BCA0 File Offset: 0x00079EA0 public static IChannel GetChannel(string name) { object syncRoot = ChannelServices.registeredChannels.SyncRoot; IChannel channel2; lock (syncRoot) { foreach (object obj in ChannelServices.registeredChannels) { IChannel channel = (IChannel)obj; if (channel.ChannelName == name && !(channel is CrossAppDomainChannel)) { return channel; } } channel2 = null; } return channel2; } /// Returns a of properties for a given proxy. /// An interface to the dictionary of properties, or null if no properties were found. /// The proxy to retrieve properties for. /// At least one of the callers that is higher in the callstack does not have permission to configure remoting types and channels. /// /// /// // Token: 0x06002565 RID: 9573 RVA: 0x0007BD6C File Offset: 0x00079F6C public static IDictionary GetChannelSinkProperties(object obj) { if (!RemotingServices.IsTransparentProxy(obj)) { throw new ArgumentException("obj must be a proxy", "obj"); } ClientIdentity clientIdentity = (ClientIdentity)RemotingServices.GetRealProxy(obj).ObjectIdentity; IMessageSink messageSink = clientIdentity.ChannelSink; ArrayList arrayList = new ArrayList(); while (messageSink != null && !(messageSink is IClientChannelSink)) { messageSink = messageSink.NextSink; } if (messageSink == null) { return new Hashtable(); } for (IClientChannelSink clientChannelSink = messageSink as IClientChannelSink; clientChannelSink != null; clientChannelSink = clientChannelSink.NextChannelSink) { arrayList.Add(clientChannelSink.Properties); } IDictionary[] array = (IDictionary[])arrayList.ToArray(typeof(IDictionary[])); return new AggregateDictionary(array); } /// Returns an array of all the URLs that can be used to reach the specified object. /// An array of strings that contains the URLs that can be used to remotely identify the object, or null if none were found. /// The object to retrieve the URL array for. /// The immediate caller does not have infrastructure permission. /// /// /// // Token: 0x06002566 RID: 9574 RVA: 0x0007BE20 File Offset: 0x0007A020 public static string[] GetUrlsForObject(MarshalByRefObject obj) { string objectUri = RemotingServices.GetObjectUri(obj); if (objectUri == null) { return new string[0]; } ArrayList arrayList = new ArrayList(); object syncRoot = ChannelServices.registeredChannels.SyncRoot; lock (syncRoot) { foreach (object obj2 in ChannelServices.registeredChannels) { if (!(obj2 is CrossAppDomainChannel)) { IChannelReceiver channelReceiver = obj2 as IChannelReceiver; if (channelReceiver != null) { arrayList.AddRange(channelReceiver.GetUrlsForUri(objectUri)); } } } } return (string[])arrayList.ToArray(typeof(string)); } /// Registers a channel with the channel services. is obsolete. Please use instead. /// The channel to register. /// The parameter is null. /// The channel has already been registered. /// At least one of the callers higher in the callstack does not have permission to configure remoting types and channels. /// /// /// // Token: 0x06002567 RID: 9575 RVA: 0x0007BF1C File Offset: 0x0007A11C [Obsolete("Use RegisterChannel(IChannel,Boolean)")] public static void RegisterChannel(IChannel chnl) { ChannelServices.RegisterChannel(chnl, false); } /// Registers a channel with the channel services. /// The channel to register. /// true ensures that security is enabled; otherwise false. Setting the value to false will not nullify the security setting done on the TCP or IPC channel. For details, see Remarks. /// The parameter is null. /// The channel has already been registered. /// At least one of the callers higher in the call stack does not have permission to configure remoting types and channels. /// Not supported in Windows 98 for and on all platforms for . Host the service using Internet Information Services (IIS) if you require a secure HTTP channel. // Token: 0x06002568 RID: 9576 RVA: 0x0007BF28 File Offset: 0x0007A128 public static void RegisterChannel(IChannel chnl, bool ensureSecurity) { if (chnl == null) { throw new ArgumentNullException("chnl"); } if (ensureSecurity) { ISecurableChannel securableChannel = chnl as ISecurableChannel; if (securableChannel == null) { throw new RemotingException(string.Format("Channel {0} is not securable while ensureSecurity is specified as true", chnl.ChannelName)); } securableChannel.IsSecured = true; } object syncRoot = ChannelServices.registeredChannels.SyncRoot; lock (syncRoot) { int num = -1; for (int i = 0; i < ChannelServices.registeredChannels.Count; i++) { IChannel channel = (IChannel)ChannelServices.registeredChannels[i]; if (channel.ChannelName == chnl.ChannelName && chnl.ChannelName != string.Empty) { throw new RemotingException("Channel " + channel.ChannelName + " already registered"); } if (channel.ChannelPriority < chnl.ChannelPriority && num == -1) { num = i; } } if (num != -1) { ChannelServices.registeredChannels.Insert(num, chnl); } else { ChannelServices.registeredChannels.Add(chnl); } IChannelReceiver channelReceiver = chnl as IChannelReceiver; if (channelReceiver != null && ChannelServices.oldStartModeTypes.Contains(chnl.GetType().ToString())) { channelReceiver.StartListening(null); } } } // Token: 0x06002569 RID: 9577 RVA: 0x0007C098 File Offset: 0x0007A298 internal static void RegisterChannelConfig(ChannelData channel) { IServerChannelSinkProvider serverChannelSinkProvider = null; IClientChannelSinkProvider clientChannelSinkProvider = null; for (int i = channel.ServerProviders.Count - 1; i >= 0; i--) { ProviderData providerData = channel.ServerProviders[i] as ProviderData; IServerChannelSinkProvider serverChannelSinkProvider2 = (IServerChannelSinkProvider)ChannelServices.CreateProvider(providerData); serverChannelSinkProvider2.Next = serverChannelSinkProvider; serverChannelSinkProvider = serverChannelSinkProvider2; } for (int j = channel.ClientProviders.Count - 1; j >= 0; j--) { ProviderData providerData2 = channel.ClientProviders[j] as ProviderData; IClientChannelSinkProvider clientChannelSinkProvider2 = (IClientChannelSinkProvider)ChannelServices.CreateProvider(providerData2); clientChannelSinkProvider2.Next = clientChannelSinkProvider; clientChannelSinkProvider = clientChannelSinkProvider2; } Type type = Type.GetType(channel.Type); if (type == null) { throw new RemotingException("Type '" + channel.Type + "' not found"); } bool flag = typeof(IChannelSender).IsAssignableFrom(type); bool flag2 = typeof(IChannelReceiver).IsAssignableFrom(type); Type[] array; object[] array2; if (flag && flag2) { array = new Type[] { typeof(IDictionary), typeof(IClientChannelSinkProvider), typeof(IServerChannelSinkProvider) }; array2 = new object[] { channel.CustomProperties, clientChannelSinkProvider, serverChannelSinkProvider }; } else if (flag) { array = new Type[] { typeof(IDictionary), typeof(IClientChannelSinkProvider) }; array2 = new object[] { channel.CustomProperties, clientChannelSinkProvider }; } else { if (!flag2) { throw new RemotingException(type + " is not a valid channel type"); } array = new Type[] { typeof(IDictionary), typeof(IServerChannelSinkProvider) }; array2 = new object[] { channel.CustomProperties, serverChannelSinkProvider }; } ConstructorInfo constructor = type.GetConstructor(array); if (constructor == null) { throw new RemotingException(type + " does not have a valid constructor"); } IChannel channel2; try { channel2 = (IChannel)constructor.Invoke(array2); } catch (TargetInvocationException ex) { throw ex.InnerException; } object syncRoot = ChannelServices.registeredChannels.SyncRoot; lock (syncRoot) { if (channel.DelayLoadAsClientChannel == "true" && !(channel2 is IChannelReceiver)) { ChannelServices.delayedClientChannels.Add(channel2); } else { ChannelServices.RegisterChannel(channel2); } } } // Token: 0x0600256A RID: 9578 RVA: 0x0007C360 File Offset: 0x0007A560 private static object CreateProvider(ProviderData prov) { Type type = Type.GetType(prov.Type); if (type == null) { throw new RemotingException("Type '" + prov.Type + "' not found"); } object[] array = new object[] { prov.CustomProperties, prov.CustomData }; object obj; try { obj = Activator.CreateInstance(type, array); } catch (Exception innerException) { if (innerException is TargetInvocationException) { innerException = ((TargetInvocationException)innerException).InnerException; } throw new RemotingException(string.Concat(new object[] { "An instance of provider '", type, "' could not be created: ", innerException.Message })); } return obj; } /// Synchronously dispatches the incoming message to the server-side chain(s) based on the URI embedded in the message. /// A reply message is returned by the call to the server-side chain. /// The message to dispatch. /// The parameter is null. /// The immediate caller does not have infrastructure permission. /// /// /// /// // Token: 0x0600256B RID: 9579 RVA: 0x0007C430 File Offset: 0x0007A630 public static IMessage SyncDispatchMessage(IMessage msg) { IMessage message = ChannelServices.CheckIncomingMessage(msg); if (message != null) { return ChannelServices.CheckReturnMessage(msg, message); } message = ChannelServices._crossContextSink.SyncProcessMessage(msg); return ChannelServices.CheckReturnMessage(msg, message); } /// Asynchronously dispatches the given message to the server-side chain(s) based on the URI embedded in the message. /// A object used to control the asynchronously dispatched message. /// The message to dispatch. /// The sink that will process the return message if it is not null. /// The parameter is null. /// The immediate caller does not have infrastructure permission. /// /// /// /// // Token: 0x0600256C RID: 9580 RVA: 0x0007C468 File Offset: 0x0007A668 public static IMessageCtrl AsyncDispatchMessage(IMessage msg, IMessageSink replySink) { IMessage message = ChannelServices.CheckIncomingMessage(msg); if (message != null) { replySink.SyncProcessMessage(ChannelServices.CheckReturnMessage(msg, message)); return null; } if (RemotingConfiguration.CustomErrorsEnabled(ChannelServices.IsLocalCall(msg))) { replySink = new ExceptionFilterSink(msg, replySink); } return ChannelServices._crossContextSink.AsyncProcessMessage(msg, replySink); } // Token: 0x0600256D RID: 9581 RVA: 0x0007C4B8 File Offset: 0x0007A6B8 private static ReturnMessage CheckIncomingMessage(IMessage msg) { IMethodMessage methodMessage = (IMethodMessage)msg; ServerIdentity serverIdentity = RemotingServices.GetIdentityForUri(methodMessage.Uri) as ServerIdentity; if (serverIdentity == null) { return new ReturnMessage(new RemotingException("No receiver for uri " + methodMessage.Uri), (IMethodCallMessage)msg); } RemotingServices.SetMessageTargetIdentity(msg, serverIdentity); return null; } // Token: 0x0600256E RID: 9582 RVA: 0x0007C50C File Offset: 0x0007A70C internal static IMessage CheckReturnMessage(IMessage callMsg, IMessage retMsg) { IMethodReturnMessage methodReturnMessage = retMsg as IMethodReturnMessage; if (methodReturnMessage != null && methodReturnMessage.Exception != null && RemotingConfiguration.CustomErrorsEnabled(ChannelServices.IsLocalCall(callMsg))) { Exception ex = new Exception("Server encountered an internal error. For more information, turn off customErrors in the server's .config file."); retMsg = new MethodResponse(ex, (IMethodCallMessage)callMsg); } return retMsg; } // Token: 0x0600256F RID: 9583 RVA: 0x0007C55C File Offset: 0x0007A75C private static bool IsLocalCall(IMessage callMsg) { return true; } /// Unregisters a particular channel from the registered channels list. /// The channel to unregister. /// The parameter is null. /// The channel is not registered. /// At least one of the callers higher in the callstack does not have permission to configure remoting types and channels. /// /// /// // Token: 0x06002570 RID: 9584 RVA: 0x0007C560 File Offset: 0x0007A760 public static void UnregisterChannel(IChannel chnl) { if (chnl == null) { throw new ArgumentNullException(); } object syncRoot = ChannelServices.registeredChannels.SyncRoot; lock (syncRoot) { for (int i = 0; i < ChannelServices.registeredChannels.Count; i++) { if (ChannelServices.registeredChannels[i] == chnl) { ChannelServices.registeredChannels.RemoveAt(i); IChannelReceiver channelReceiver = chnl as IChannelReceiver; if (channelReceiver != null) { channelReceiver.StopListening(null); } return; } } throw new RemotingException("Channel not registered"); } } // Token: 0x06002571 RID: 9585 RVA: 0x0007C610 File Offset: 0x0007A810 internal static object[] GetCurrentChannelInfo() { ArrayList arrayList = new ArrayList(); object syncRoot = ChannelServices.registeredChannels.SyncRoot; lock (syncRoot) { foreach (object obj in ChannelServices.registeredChannels) { IChannelReceiver channelReceiver = obj as IChannelReceiver; if (channelReceiver != null) { object channelData = channelReceiver.ChannelData; if (channelData != null) { arrayList.Add(channelData); } } } } return arrayList.ToArray(); } // Token: 0x04000EA9 RID: 3753 private static ArrayList registeredChannels = new ArrayList(); // Token: 0x04000EAA RID: 3754 private static ArrayList delayedClientChannels = new ArrayList(); // Token: 0x04000EAB RID: 3755 private static CrossContextChannel _crossContextSink = new CrossContextChannel(); // Token: 0x04000EAC RID: 3756 internal static string CrossContextUrl = "__CrossContext"; // Token: 0x04000EAD RID: 3757 private static IList oldStartModeTypes = new string[] { "Novell.Zenworks.Zmd.Public.UnixServerChannel", "Novell.Zenworks.Zmd.Public.UnixChannel" }; } }