[System.Security.SecurityCritical] // auto-generated public void StoreAndDispatch(IServerChannelSink sink, Object state) { Store(sink, state); FlipRememberedStack(); CrossContextChannel.DoAsyncDispatch(_asyncMsg, null); } // Store
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); }
public static ServerProcessing DispatchMessage( IServerChannelSinkStack sinkStack, IMessage msg, out IMessage replyMsg) { ServerProcessing processing = ServerProcessing.Complete; replyMsg = null; try { if (null == msg) { throw new ArgumentNullException("msg"); } BCLDebug.Trace("REMOTE", "Dispatching for URI " + InternalSink.GetURI(msg)); // we must switch to the target context of the object and call the context chains etc... // Currenly XContextChannel does exactly so. So this method is just a wrapper.. // Make sure that incoming calls are counted as a remote call. This way it // makes more sense on a server. IncrementRemoteCalls(); // Check if the object has been disconnected or if it is // a well known object then we have to create it lazily. ServerIdentity srvId = CheckDisconnectedOrCreateWellKnownObject(msg); // Make sure that this isn't an AppDomain object since we don't allow // calls to the AppDomain from out of process (and x-process calls // are always dispatched through this method) if (srvId.ServerType == typeof(System.AppDomain)) { throw new RemotingException( Environment.GetResourceString( "Remoting_AppDomainsCantBeCalledRemotely")); } IMethodCallMessage mcm = msg as IMethodCallMessage; if (mcm == null) { // It's a plain IMessage, so just check to make sure that the // target object implements IMessageSink and dispatch synchronously. if (!typeof(IMessageSink).IsAssignableFrom(srvId.ServerType)) { throw new RemotingException( Environment.GetResourceString( "Remoting_AppDomainsCantBeCalledRemotely")); } processing = ServerProcessing.Complete; replyMsg = ChannelServices.GetCrossContextChannelSink().SyncProcessMessage(msg); } else { // It's an IMethodCallMessage. // Check if the method is one way. Dispatch one way calls in // an asynchronous manner MethodInfo method = (MethodInfo)mcm.MethodBase; // X-process / X-machine calls should be to non-static // public methods only! Non-public or static methods can't // be called remotely. if (!IsMethodReallyPublic(method) && !RemotingServices.IsMethodAllowedRemotely(method)) { throw new RemotingException( Environment.GetResourceString( "Remoting_NonPublicOrStaticCantBeCalledRemotely")); } RemotingMethodCachedData cache = (RemotingMethodCachedData) InternalRemotingServices.GetReflectionCachedData(method); /* * FUTURE: * Dispatching asynchronously was cut from v1. We should reactivate * the following code in v1.x or v2. * * // look for async method version * MethodInfo begin; * MethodInfo end; * ServerChannelSinkStack serverSinkStack = sinkStack as ServerChannelSinkStack; * if ((sinkStack != null) && * cache.GetAsyncMethodVersion(out begin, out end)) * { * processing = ServerProcessing.Async; * IMessage asyncMsg = * new AsyncMethodCallMessageWrapper( * (IMethodCallMessage)msg, * begin, * new AsyncCallback(sinkStack.ServerCallback), * null); * serverSinkStack.AsyncMessage = asyncMsg; * serverSinkStack.AsyncEnd = end; * serverSinkStack.Message = (IMethodCallMessage)msg; * asyncMsg.Properties["__SinkStack"] = sinkStack; * * // We don't dispatch yet. That happens when the server transport sink * // eventually calls sinkStack.StoreAndDispatch(...). * } * else */ if (RemotingServices.IsOneWay(method)) { processing = ServerProcessing.OneWay; ChannelServices.GetCrossContextChannelSink().AsyncProcessMessage(msg, null); } else { // regular processing processing = ServerProcessing.Complete; if (!srvId.ServerType.IsContextful) { Object[] args = new Object[] { msg, srvId.ServerContext }; replyMsg = (IMessage)CrossContextChannel.SyncProcessMessageCallback(args); } else { replyMsg = ChannelServices.GetCrossContextChannelSink().SyncProcessMessage(msg); } } } // end of case for IMethodCallMessage } catch (Exception e) { if (processing != ServerProcessing.OneWay) { try { IMethodCallMessage mcm = (IMethodCallMessage)((msg != null)?msg:new ErrorMessage()); replyMsg = (IMessage) new ReturnMessage(e, mcm); if (msg != null) { ((ReturnMessage)replyMsg).SetLogicalCallContext( (LogicalCallContext) msg.Properties[Message.CallContextKey]); } } catch (Exception) { // Fatal exception .. ignore } } } return(processing); } // DispatchMessage
public void StoreAndDispatch(IServerChannelSink sink, object state) { this.Store(sink, state); this.FlipRememberedStack(); CrossContextChannel.DoAsyncDispatch(this._asyncMsg, null); }
public static ServerProcessing DispatchMessage(IServerChannelSinkStack sinkStack, IMessage msg, out IMessage replyMsg) { ServerProcessing complete = ServerProcessing.Complete; replyMsg = null; try { if (msg == null) { throw new ArgumentNullException("msg"); } IncrementRemoteCalls(); ServerIdentity identity = CheckDisconnectedOrCreateWellKnownObject(msg); if (identity.ServerType == typeof(AppDomain)) { throw new RemotingException(Environment.GetResourceString("Remoting_AppDomainsCantBeCalledRemotely")); } IMethodCallMessage message = msg as IMethodCallMessage; if (message == null) { if (!typeof(IMessageSink).IsAssignableFrom(identity.ServerType)) { throw new RemotingException(Environment.GetResourceString("Remoting_AppDomainsCantBeCalledRemotely")); } complete = ServerProcessing.Complete; replyMsg = GetCrossContextChannelSink().SyncProcessMessage(msg); return(complete); } MethodInfo methodBase = (MethodInfo)message.MethodBase; if (!IsMethodReallyPublic(methodBase) && !RemotingServices.IsMethodAllowedRemotely(methodBase)) { throw new RemotingException(Environment.GetResourceString("Remoting_NonPublicOrStaticCantBeCalledRemotely")); } InternalRemotingServices.GetReflectionCachedData((MethodBase)methodBase); if (RemotingServices.IsOneWay(methodBase)) { complete = ServerProcessing.OneWay; GetCrossContextChannelSink().AsyncProcessMessage(msg, null); return(complete); } complete = ServerProcessing.Complete; if (!identity.ServerType.IsContextful) { object[] args = new object[] { msg, identity.ServerContext }; replyMsg = (IMessage)CrossContextChannel.SyncProcessMessageCallback(args); return(complete); } replyMsg = GetCrossContextChannelSink().SyncProcessMessage(msg); } catch (Exception exception) { if (complete == ServerProcessing.OneWay) { return(complete); } try { IMethodCallMessage mcm = (msg != null) ? ((IMethodCallMessage)msg) : ((IMethodCallMessage) new ErrorMessage()); replyMsg = new ReturnMessage(exception, mcm); if (msg != null) { ((ReturnMessage)replyMsg).SetLogicalCallContext((LogicalCallContext)msg.Properties[Message.CallContextKey]); } } catch (Exception) { } } return(complete); }