public static ServerProcessing DispatchMessage(IServerChannelSinkStack sinkStack, IMessage msg, out IMessage replyMsg) { ServerProcessing serverProcessing = ServerProcessing.Complete; replyMsg = (IMessage)null; try { if (msg == null) { throw new ArgumentNullException("msg"); } ChannelServices.IncrementRemoteCalls(); ServerIdentity wellKnownObject = ChannelServices.CheckDisconnectedOrCreateWellKnownObject(msg); if (wellKnownObject.ServerType == typeof(AppDomain)) { throw new RemotingException(Environment.GetResourceString("Remoting_AppDomainsCantBeCalledRemotely")); } IMethodCallMessage methodCallMessage = msg as IMethodCallMessage; if (methodCallMessage == null) { if (!typeof(IMessageSink).IsAssignableFrom(wellKnownObject.ServerType)) { throw new RemotingException(Environment.GetResourceString("Remoting_AppDomainsCantBeCalledRemotely")); } serverProcessing = ServerProcessing.Complete; replyMsg = ChannelServices.GetCrossContextChannelSink().SyncProcessMessage(msg); } else { MethodInfo mi = (MethodInfo)methodCallMessage.MethodBase; if (!ChannelServices.IsMethodReallyPublic(mi) && !RemotingServices.IsMethodAllowedRemotely((MethodBase)mi)) { throw new RemotingException(Environment.GetResourceString("Remoting_NonPublicOrStaticCantBeCalledRemotely")); } InternalRemotingServices.GetReflectionCachedData((MethodBase)mi); if (RemotingServices.IsOneWay((MethodBase)mi)) { serverProcessing = ServerProcessing.OneWay; ChannelServices.GetCrossContextChannelSink().AsyncProcessMessage(msg, (IMessageSink)null); } else { serverProcessing = ServerProcessing.Complete; if (!wellKnownObject.ServerType.IsContextful) { object[] args = new object[2] { (object)msg, (object)wellKnownObject.ServerContext }; replyMsg = (IMessage)CrossContextChannel.SyncProcessMessageCallback(args); } else { replyMsg = ChannelServices.GetCrossContextChannelSink().SyncProcessMessage(msg); } } } } catch (Exception ex1) { if (serverProcessing != ServerProcessing.OneWay) { try { IMethodCallMessage mcm = msg != null ? (IMethodCallMessage)msg : (IMethodCallMessage) new ErrorMessage(); replyMsg = (IMessage) new ReturnMessage(ex1, mcm); if (msg != null) { ((ReturnMessage)replyMsg).SetLogicalCallContext((LogicalCallContext)msg.Properties[(object)Message.CallContextKey]); } } catch (Exception ex2) { } } } return(serverProcessing); }