18 private static volatile object[] s_currentChannelData;
20 private static object s_channelLock;
22 private static volatile RegisteredChannelList s_registeredChannels;
27 private unsafe
static volatile Perf_Contexts* perf_Contexts;
29 private static bool unloadHandlerRegistered;
31 internal static object[] CurrentChannelData
36 if (s_currentChannelData ==
null)
40 return s_currentChannelData;
44 private static long remoteCalls
52 Thread.
GetDomain().RemotingData.ChannelServicesData.remoteCalls = value;
64 RegisteredChannelList registeredChannelList = s_registeredChannels;
65 int count = registeredChannelList.Count;
73 for (
int i = 0; i < count; i++)
75 IChannel channel = registeredChannelList.GetChannel(i);
76 if (!(channel is CrossAppDomainChannel))
78 array[num2++] = channel;
85 [SecuritySafeCritical]
88 s_currentChannelData =
null;
89 s_channelLock =
new object();
90 s_registeredChannels =
new RegisteredChannelList();
91 perf_Contexts = GetPrivateContextsPerfCounters();
92 unloadHandlerRegistered =
false;
95 private ChannelServices()
101 private unsafe
static extern Perf_Contexts* GetPrivateContextsPerfCounters();
111 [SecuritySafeCritical]
115 RegisterChannelInternal(chnl, ensureSecurity);
123 [SecuritySafeCritical]
124 [Obsolete(
"Use System.Runtime.Remoting.ChannelServices.RegisterChannel(IChannel chnl, bool ensureSecurity) instead.",
false)]
128 RegisterChannelInternal(chnl, ensureSecurity:
false);
132 internal unsafe
static void RegisterChannelInternal(
IChannel chnl,
bool ensureSecurity)
138 bool lockTaken =
false;
144 RegisteredChannelList registeredChannelList = s_registeredChannels;
145 if (channelName !=
null && channelName.Length != 0 && -1 != registeredChannelList.FindChannelIndex(chnl.
ChannelName))
151 ISecurableChannel securableChannel = chnl as ISecurableChannel;
152 if (securableChannel ==
null)
154 throw new RemotingException(
Environment.GetResourceString(
"Remoting_Channel_CannotBeSecured", chnl.
ChannelName ?? chnl.ToString()));
156 securableChannel.IsSecured = ensureSecurity;
158 RegisteredChannel[] registeredChannels = registeredChannelList.RegisteredChannels;
159 RegisteredChannel[] array =
null;
160 array = ((registeredChannels !=
null) ?
new RegisteredChannel[registeredChannels.Length + 1] :
new RegisteredChannel[1]);
161 if (!unloadHandlerRegistered && !(chnl is CrossAppDomainChannel))
163 AppDomain.CurrentDomain.DomainUnload += UnloadHandler;
164 unloadHandlerRegistered =
true;
168 for (i = 0; i < registeredChannels.Length; i++)
170 RegisteredChannel registeredChannel = registeredChannels[i];
171 if (channelPriority > registeredChannel.Channel.ChannelPriority)
173 array[i] =
new RegisteredChannel(chnl);
176 array[i] = registeredChannel;
178 if (i == registeredChannels.Length)
180 array[registeredChannels.Length] =
new RegisteredChannel(chnl);
184 for (; i < registeredChannels.Length; i++)
186 array[i + 1] = registeredChannels[i];
189 if (perf_Contexts !=
null)
191 perf_Contexts->cChannels++;
193 s_registeredChannels =
new RegisteredChannelList(array);
194 RefreshChannelData();
210 [SecuritySafeCritical]
214 bool lockTaken =
false;
221 RegisteredChannelList registeredChannelList = s_registeredChannels;
222 int num = registeredChannelList.FindChannelIndex(chnl);
227 RegisteredChannel[] registeredChannels = registeredChannelList.RegisteredChannels;
228 RegisteredChannel[] array =
null;
229 array =
new RegisteredChannel[registeredChannels.Length - 1];
233 while (num3 < registeredChannels.Length)
241 array[num2] = registeredChannels[num3];
246 if (perf_Contexts !=
null)
248 perf_Contexts->cChannels--;
250 s_registeredChannels =
new RegisteredChannelList(array);
252 RefreshChannelData();
264 internal static IMessageSink CreateMessageSink(
string url,
object data, out
string objectURI)
268 RegisteredChannelList registeredChannelList = s_registeredChannels;
269 int count = registeredChannelList.Count;
270 for (
int i = 0; i < count; i++)
272 if (registeredChannelList.IsSender(i))
276 if (messageSink !=
null)
282 if (objectURI ==
null)
290 internal static IMessageSink CreateMessageSink(
object data)
293 return CreateMessageSink(
null, data, out objectURI);
303 RegisteredChannelList registeredChannelList = s_registeredChannels;
304 int num = registeredChannelList.FindChannelIndex(name);
307 IChannel channel = registeredChannelList.GetChannel(num);
308 if (channel is CrossAppDomainChannel || channel is CrossContextChannel)
328 RegisteredChannelList registeredChannelList = s_registeredChannels;
329 int count = registeredChannelList.Count;
333 if (identity !=
null)
335 string objURI = identity.ObjURI;
338 for (
int i = 0; i < count; i++)
340 if (registeredChannelList.IsReceiver(i))
344 string[] urlsForUri = ((
IChannelReceiver)registeredChannelList.GetChannel(i)).GetUrlsForUri(objURI);
345 for (
int j = 0; j < urlsForUri.Length; j++)
347 hashtable.
Add(urlsForUri[j], urlsForUri[j]);
358 string[] array =
new string[keys.
Count];
360 foreach (
string item
in keys)
368 internal static IMessageSink GetChannelSinkForProxy(
object obj)
374 RemotingProxy remotingProxy = realProxy as RemotingProxy;
375 if (remotingProxy !=
null)
377 Identity identityObject = remotingProxy.IdentityObject;
378 result = identityObject.ChannelSink;
388 [SecuritySafeCritical]
392 IMessageSink channelSinkForProxy = GetChannelSinkForProxy(obj);
394 if (clientChannelSink !=
null)
400 if (properties !=
null)
402 arrayList.
Add(properties);
406 while (clientChannelSink !=
null);
407 return new AggregateDictionary(arrayList);
410 if (dictionary !=
null)
417 internal static IMessageSink GetCrossContextChannelSink()
419 if (xCtxChannel ==
null)
421 xCtxChannel = CrossContextChannel.MessageSink;
427 internal unsafe
static void IncrementRemoteCalls(
long cCalls)
429 remoteCalls += cCalls;
430 if (perf_Contexts !=
null)
432 perf_Contexts->cRemoteCalls += (int)cCalls;
437 internal static void IncrementRemoteCalls()
439 IncrementRemoteCalls(1L);
443 internal static void RefreshChannelData()
445 bool lockTaken =
false;
450 s_currentChannelData = CollectChannelDataFromChannels();
462 private static object[] CollectChannelDataFromChannels()
464 RemotingServices.RegisterWellKnownChannels();
465 RegisteredChannelList registeredChannelList = s_registeredChannels;
466 int count = registeredChannelList.Count;
467 int receiverCount = registeredChannelList.ReceiverCount;
468 object[] array =
new object[receiverCount];
472 for (; i < count; i++)
474 IChannel channel = registeredChannelList.GetChannel(i);
477 throw new RemotingException(Environment.GetResourceString(
"Remoting_ChannelNotRegistered",
""));
479 if (registeredChannelList.IsReceiver(i))
481 if ((array[num2] = ((IChannelReceiver)channel).ChannelData) !=
null)
488 if (num != receiverCount)
490 object[] array2 =
new object[num];
492 for (
int j = 0; j < receiverCount; j++)
494 object obj = array[j];
497 array2[num3++] = obj;
505 private static bool IsMethodReallyPublic(
MethodInfo mi)
516 foreach (Type type
in genericArguments)
544 IncrementRemoteCalls();
545 ServerIdentity serverIdentity = CheckDisconnectedOrCreateWellKnownObject(msg);
546 if (serverIdentity.ServerType == typeof(
AppDomain))
551 if (methodCallMessage !=
null)
554 if (!IsMethodReallyPublic(methodInfo) && !
RemotingServices.IsMethodAllowedRemotely(methodInfo))
562 if (serverIdentity.ServerType.IsContextful)
565 return serverProcessing;
567 object[] args =
new object[2]
570 serverIdentity.ServerContext
572 replyMsg = (
IMessage)CrossContextChannel.SyncProcessMessageCallback(args);
573 return serverProcessing;
577 return serverProcessing;
579 if (!typeof(
IMessageSink).IsAssignableFrom(serverIdentity.ServerType))
585 return serverProcessing;
596 IMessage message =
new ErrorMessage();
607 return serverProcessing;
610 return serverProcessing;
614 return serverProcessing;
617 return serverProcessing;
637 IncrementRemoteCalls();
638 if (!(msg is TransitionCall))
640 CheckDisconnectedOrCreateWellKnownObject(msg);
644 IMessageSink crossContextChannelSink = GetCrossContextChannelSink();
662 IMessage message2 =
new ErrorMessage();
703 IncrementRemoteCalls();
704 if (!(msg is TransitionCall))
706 CheckDisconnectedOrCreateWellKnownObject(msg);
713 if (replySink !=
null)
743 if (provider ==
null)
745 return new DispatchChannelSink();
748 while (serverChannelSinkProvider.
Next !=
null)
750 serverChannelSinkProvider = serverChannelSinkProvider.
Next;
752 serverChannelSinkProvider.
Next =
new DispatchChannelSinkProvider();
754 serverChannelSinkProvider.
Next =
null;
759 internal static ServerIdentity CheckDisconnectedOrCreateWellKnownObject(
IMessage msg)
761 ServerIdentity serverIdentity = InternalSink.GetServerIdentity(msg);
762 if (serverIdentity ==
null || serverIdentity.IsRemoteDisconnected())
764 string uRI = InternalSink.GetURI(msg);
767 ServerIdentity serverIdentity2 = RemotingConfigHandler.CreateWellKnownObject(uRI);
768 if (serverIdentity2 !=
null)
770 serverIdentity = serverIdentity2;
774 if (serverIdentity ==
null || serverIdentity.IsRemoteDisconnected())
776 string uRI2 = InternalSink.GetURI(msg);
777 throw new RemotingException(
Environment.GetResourceString(
"Remoting_Disconnected", uRI2));
779 return serverIdentity;
783 internal static void UnloadHandler(
object sender, EventArgs e)
785 StopListeningOnAllChannels();
789 private static void StopListeningOnAllChannels()
793 RegisteredChannelList registeredChannelList = s_registeredChannels;
794 int count = registeredChannelList.Count;
795 for (
int i = 0; i < count; i++)
797 if (registeredChannelList.IsReceiver(i))
799 IChannelReceiver channelReceiver = (IChannelReceiver)registeredChannelList.GetChannel(i);
800 channelReceiver.StopListening(
null);
810 internal static void NotifyProfiler(
IMessage msg, RemotingProfilerEvent profilerEvent)
812 switch (profilerEvent)
814 case RemotingProfilerEvent.ClientSend:
815 if (RemotingServices.CORProfilerTrackRemoting())
817 RemotingServices.CORProfilerRemotingClientSendingMessage(out Guid id2, fIsAsync:
false);
818 if (RemotingServices.CORProfilerTrackRemotingCookie())
824 case RemotingProfilerEvent.ClientReceive:
826 if (!RemotingServices.CORProfilerTrackRemoting())
830 Guid
id = Guid.Empty;
831 if (RemotingServices.CORProfilerTrackRemotingCookie())
833 object obj = msg.
Properties[
"CORProfilerCookie"];
839 RemotingServices.CORProfilerRemotingClientReceivingReply(
id, fIsAsync:
false);
846 internal static string FindFirstHttpUrlForObject(
string objectUri)
848 if (objectUri ==
null)
852 RegisteredChannelList registeredChannelList = s_registeredChannels;
853 int count = registeredChannelList.Count;
854 for (
int i = 0; i < count; i++)
856 if (!registeredChannelList.IsReceiver(i))
860 IChannelReceiver channelReceiver = (IChannelReceiver)registeredChannelList.GetChannel(i);
861 string fullName = channelReceiver.GetType().FullName;
862 if (
string.CompareOrdinal(fullName,
"System.Runtime.Remoting.Channels.Http.HttpChannel") == 0 ||
string.CompareOrdinal(fullName,
"System.Runtime.Remoting.Channels.Http.HttpServerChannel") == 0)
864 string[] urlsForUri = channelReceiver.GetUrlsForUri(objectUri);
865 if (urlsForUri !=
null && urlsForUri.Length != 0)
867 return urlsForUri[0];
static void RegisterChannel(IChannel chnl)
Registers a channel with the channel services. M:System.Runtime.Remoting.Channels....
static string [] GetUrlsForObject(MarshalByRefObject obj)
Returns an array of all the URLs that can be used to reach the specified object.
int ChannelPriority
Gets the priority of the channel.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Describes a set of security permissions applied to code. This class cannot be inherited.
virtual void Add(object key, object value)
Adds an element with the specified key and value into the T:System.Collections.Hashtable.
IServerChannelSinkProvider Next
Gets or sets the next sink provider in the channel sink provider chain.
string ChannelName
Gets the name of the channel.
Holds a message returned in response to a method call on a remote object.
IDictionary Properties
Gets a dictionary through which properties on the sink can be accessed.
MethodBase MethodBase
Gets the T:System.Reflection.MethodBase of the called method.
Creates server channel sinks for the server channel through which remoting messages flow.
Discovers the attributes of a method and provides access to method metadata.
IMessage SyncProcessMessage(IMessage msg)
Synchronously processes the given message.
static IServerChannelSink CreateServerChannelSinkChain(IServerChannelSinkProvider provider, IChannelReceiver channel)
Creates a channel sink chain for the specified channel.
Defines the method call message interface.
static IChannel GetChannel(string name)
Returns a registered channel with the specified name.
Provides base functionality for proxies.
Provides a mechanism that synchronizes access to objects.
Provides required functions and properties for the receiver channels.
IDictionary Properties
Gets an T:System.Collections.IDictionary that represents a collection of the message's properties.
Provides the stack functionality for a stack of server channel sinks.
Represents an application domain, which is an isolated environment where applications execute....
bool IsStatic
Gets a value indicating whether the method is static.
ServerProcessing
Indicates the status of the server message processing.
Provides methods used for security and transport sinks.
Provides a way to control asynchronous messages after they have dispatched using the M:System....
SecurityAction
Specifies the security actions that can be performed using declarative security.
static void Enter(object obj)
Acquires an exclusive lock on the specified object.
Provides information about, and means to manipulate, the current environment and platform....
virtual bool IsGenericMethod
Gets a value indicating whether the method is generic.
Represents a collection of key/value pairs that are organized based on the hash code of the key....
virtual ICollection Keys
Gets an T:System.Collections.ICollection containing the keys in the T:System.Collections....
LogicalCallContext LogicalCallContext
Gets the T:System.Runtime.Remoting.Messaging.LogicalCallContext for the current method call.
static IDictionary GetChannelSinkProperties(object obj)
Returns a T:System.Collections.IDictionary of properties for a given proxy.
IMessageSink CreateMessageSink(string url, object remoteChannelData, out string objectURI)
Returns a channel message sink that delivers messages to the specified URL or channel data object.
static void Exit(object obj)
Releases an exclusive lock on the specified object.
static void PrepareConstrainedRegions()
Designates a body of code as a constrained execution region (CER).
Provides static methods to aid with remoting channel registration, resolution, and URL discovery....
IMessageCtrl AsyncProcessMessage(IMessage msg, IMessageSink replySink)
Asynchronously processes the given message.
Defines utility methods for use by the .NET Framework remoting infrastructure.
static ServerProcessing DispatchMessage(IServerChannelSinkStack sinkStack, IMessage msg, out IMessage replyMsg)
Dispatches incoming remote calls.
Provides information about methods and constructors.
bool IsPublic
Gets a value indicating whether this is a public method.
IClientChannelSink NextChannelSink
Gets the next client channel sink in the client sink chain.
MethodImplOptions
Defines the details of how a method is implemented.
static AppDomain GetDomain()
Returns the current domain in which the current thread is running.
Provides a set of properties that are carried with the execution code path during remote method calls...
Defines the method message interface.
override Type [] GetGenericArguments()
Returns an array of T:System.Type objects that represent the type arguments of a generic method or th...
virtual int Add(object value)
Adds an object to the end of the T:System.Collections.ArrayList.
static bool IsTransparentProxy(object proxy)
Returns a Boolean value that indicates whether the given object is a transparent proxy or a real obje...
Contains communication data sent between cooperating message sinks.
static void RegisterChannel(IChannel chnl, bool ensureSecurity)
Registers a channel with the channel services.
static unsafe void UnregisterChannel(IChannel chnl)
Unregisters a particular channel from the registered channels list.
static RealProxy GetRealProxy(object proxy)
Returns the real proxy backing the specified transparent proxy.
static IMessageCtrl AsyncDispatchMessage(IMessage msg, IMessageSink replySink)
Asynchronously dispatches the given message to the server-side chain(s) based on the URI embedded in ...
static bool IsOneWay(MethodBase method)
Returns a Boolean value that indicates whether the client that called the method specified in the giv...
Provides conduits for messages that cross remoting boundaries.
IServerChannelSink CreateSink(IChannelReceiver channel)
Creates a sink chain.
Represents errors that occur during application execution.To browse the .NET Framework source code fo...
Defines the interface for a message sink.
Provides required functions and properties for client channel sinks.
int Count
Gets the number of elements contained in the T:System.Collections.ICollection.
static IMessage SyncDispatchMessage(IMessage msg)
Synchronously dispatches the incoming message to the server-side chain(s) based on the URI embedded i...
The exception that is thrown when an invoked method is not supported, or when there is an attempt to ...
Defines size, enumerators, and synchronization methods for all nongeneric collections.
SecurityPermissionFlag
Specifies access flags for the security permission object.
Provides several methods for using and publishing remoted objects and proxies. This class cannot be i...
Represents a nongeneric collection of key/value pairs.
Provides required functions and properties for the sender channels.
static IChannel [] RegisteredChannels
Gets a list of currently registered channels.
The exception that is thrown when something has gone wrong during remoting.
Provides a set of static methods and properties that provide support for compilers....
Implements the T:System.Collections.IList interface using an array whose size is dynamically increase...
Enables access to objects across application domain boundaries in applications that support remoting.
Creates and controls a thread, sets its priority, and gets its status.