Пример #1
0
        public static IMessage SyncDispatchMessage(IMessage msg)
        {
            IMessage msgRet    = null;
            bool     fIsOneWay = false;

            try
            {
                if (null == msg)
                {
                    throw new ArgumentNullException("msg");
                }



                // For ContextBoundObject's,
                // 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();

                // FUTURE: transitionCall needs to implement IMethodMessage ..
                if (!(msg is TransitionCall))
                {
                    // Check if the object has been disconnected or if it is
                    // a well known object then we have to create it lazily.
                    CheckDisconnectedOrCreateWellKnownObject(msg);

                    MethodBase method = ((IMethodMessage)msg).MethodBase;

                    // Check if the method is one way. Dispatch one way calls in
                    // an asynchronous manner
                    fIsOneWay = RemotingServices.IsOneWay(method);
                }

                // FUTURE: for MBR objects we could skip the x-ctx channel sink
                IMessageSink nextSink = ChannelServices.GetCrossContextChannelSink();

                if (!fIsOneWay)
                {
                    msgRet = nextSink.SyncProcessMessage(msg);
                }
                else
                {
                    nextSink.AsyncProcessMessage(msg, null);
                }
            }
            catch (Exception e)
            {
                if (!fIsOneWay)
                {
                    try
                    {
                        IMethodCallMessage mcm =
                            (IMethodCallMessage)((msg != null)?msg:new ErrorMessage());
                        msgRet = (IMessage) new ReturnMessage(e, mcm);
                        if (msg != null)
                        {
                            ((ReturnMessage)msgRet).SetLogicalCallContext(
                                mcm.LogicalCallContext);
                        }
                    }
                    catch (Exception)
                    {
                        // Fatal exception .. ignore
                    }
                }
            }

            return(msgRet);
        }
        [System.Security.SecurityCritical]  // auto-generated
        internal static void RegisterChannel()
        {
            CrossAppDomainChannel adc = CrossAppDomainChannel.AppDomainChannel;

            ChannelServices.RegisterChannelInternal((IChannel)adc, false /*ensureSecurity*/);
        }
Пример #3
0
 public IMessage SyncProcessMessage(IMessage msg)
 {
     return(_next.SyncProcessMessage(ChannelServices.CheckReturnMessage(_call, msg)));
 }
Пример #4
0
        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..

                // FUTURE: This dispatches MarshalByRef objects in the default context
                // Ideally, MarshalByRef objects should be dispatched in any context.

                // 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 ((!method.IsPublic || method.IsStatic) &&
                        !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;
                        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 ServerProcessing ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, out IMessage responseMsg, out ITransportHeaders responseHeaders, out Stream responseStream)
 {
     responseHeaders = null;
     responseStream  = null;
     return(ChannelServices.DispatchMessage(sinkStack, requestMsg, out responseMsg));
 }
Пример #6
0
        internal static void RegisterChannel()
        {
            CrossAppDomainChannel adc = CrossAppDomainChannel.AppDomainChannel;

            ChannelServices.RegisterChannelInternal((IChannel)adc);
        }
        internal static void RegisterChannel()
        {
            CrossAppDomainChannel appDomainChannel = CrossAppDomainChannel.AppDomainChannel;

            ChannelServices.RegisterChannelInternal(appDomainChannel, false);
        }
Пример #8
0
        [System.Security.SecurityCritical]  // auto-generated_required
        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);

                    /*
                     *
                     *
                     *
                     *
                     *
                     *
                     *
                     *
                     *
                     *
                     *
                     *
                     *
                     *
                     *
                     *
                     *
                     *
                     *
                     *
                     *
                     *
                     *
                     *
                     *
                     *
                     *
                     */
                    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
Пример #9
0
 public static void RegisterChannel(IChannel chnl)
 {
     ChannelServices.RegisterChannelInternal(chnl, false);
 }
Пример #10
0
        internal unsafe static void RegisterChannelInternal(IChannel chnl, bool ensureSecurity)
        {
            if (chnl == null)
            {
                throw new ArgumentNullException("chnl");
            }
            bool flag = false;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                Monitor.Enter(ChannelServices.s_channelLock, ref flag);
                string channelName = chnl.ChannelName;
                RegisteredChannelList registeredChannelList = ChannelServices.s_registeredChannels;
                if (channelName != null && channelName.Length != 0 && -1 != registeredChannelList.FindChannelIndex(chnl.ChannelName))
                {
                    throw new RemotingException(Environment.GetResourceString("Remoting_ChannelNameAlreadyRegistered", new object[]
                    {
                        chnl.ChannelName
                    }));
                }
                if (ensureSecurity)
                {
                    ISecurableChannel securableChannel = chnl as ISecurableChannel;
                    if (securableChannel == null)
                    {
                        throw new RemotingException(Environment.GetResourceString("Remoting_Channel_CannotBeSecured", new object[]
                        {
                            chnl.ChannelName ?? chnl.ToString()
                        }));
                    }
                    securableChannel.IsSecured = ensureSecurity;
                }
                RegisteredChannel[] registeredChannels = registeredChannelList.RegisteredChannels;
                RegisteredChannel[] array;
                if (registeredChannels == null)
                {
                    array = new RegisteredChannel[1];
                }
                else
                {
                    array = new RegisteredChannel[registeredChannels.Length + 1];
                }
                if (!ChannelServices.unloadHandlerRegistered && !(chnl is CrossAppDomainChannel))
                {
                    AppDomain.CurrentDomain.DomainUnload   += ChannelServices.UnloadHandler;
                    ChannelServices.unloadHandlerRegistered = true;
                }
                int channelPriority = chnl.ChannelPriority;
                int i;
                for (i = 0; i < registeredChannels.Length; i++)
                {
                    RegisteredChannel registeredChannel = registeredChannels[i];
                    if (channelPriority > registeredChannel.Channel.ChannelPriority)
                    {
                        array[i] = new RegisteredChannel(chnl);
                        break;
                    }
                    array[i] = registeredChannel;
                }
                if (i == registeredChannels.Length)
                {
                    array[registeredChannels.Length] = new RegisteredChannel(chnl);
                }
                else
                {
                    while (i < registeredChannels.Length)
                    {
                        array[i + 1] = registeredChannels[i];
                        i++;
                    }
                }
                if (ChannelServices.perf_Contexts != null)
                {
                    ChannelServices.perf_Contexts->cChannels++;
                }
                ChannelServices.s_registeredChannels = new RegisteredChannelList(array);
                ChannelServices.RefreshChannelData();
            }
            finally
            {
                if (flag)
                {
                    Monitor.Exit(ChannelServices.s_channelLock);
                }
            }
        }
Пример #11
0
 internal static void UnloadHandler(object sender, EventArgs e)
 {
     ChannelServices.StopListeningOnAllChannels();
 }
Пример #12
0
 public static void RegisterChannel(IChannel chnl, bool ensureSecurity)
 {
     ChannelServices.RegisterChannelInternal(chnl, ensureSecurity);
 }
Пример #13
0
        public static ServerProcessing DispatchMessage(IServerChannelSinkStack sinkStack, IMessage msg, out IMessage replyMsg)
        {
            ServerProcessing serverProcessing = ServerProcessing.Complete;

            replyMsg = null;
            try
            {
                if (msg == null)
                {
                    throw new ArgumentNullException("msg");
                }
                ChannelServices.IncrementRemoteCalls();
                ServerIdentity serverIdentity = ChannelServices.CheckDisconnectedOrCreateWellKnownObject(msg);
                if (serverIdentity.ServerType == typeof(AppDomain))
                {
                    throw new RemotingException(Environment.GetResourceString("Remoting_AppDomainsCantBeCalledRemotely"));
                }
                IMethodCallMessage methodCallMessage = msg as IMethodCallMessage;
                if (methodCallMessage == null)
                {
                    if (!typeof(IMessageSink).IsAssignableFrom(serverIdentity.ServerType))
                    {
                        throw new RemotingException(Environment.GetResourceString("Remoting_AppDomainsCantBeCalledRemotely"));
                    }
                    serverProcessing = ServerProcessing.Complete;
                    replyMsg         = ChannelServices.GetCrossContextChannelSink().SyncProcessMessage(msg);
                }
                else
                {
                    MethodInfo methodInfo = (MethodInfo)methodCallMessage.MethodBase;
                    if (!ChannelServices.IsMethodReallyPublic(methodInfo) && !RemotingServices.IsMethodAllowedRemotely(methodInfo))
                    {
                        throw new RemotingException(Environment.GetResourceString("Remoting_NonPublicOrStaticCantBeCalledRemotely"));
                    }
                    RemotingMethodCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(methodInfo);
                    if (RemotingServices.IsOneWay(methodInfo))
                    {
                        serverProcessing = ServerProcessing.OneWay;
                        ChannelServices.GetCrossContextChannelSink().AsyncProcessMessage(msg, null);
                    }
                    else
                    {
                        serverProcessing = ServerProcessing.Complete;
                        if (!serverIdentity.ServerType.IsContextful)
                        {
                            object[] args = new object[]
                            {
                                msg,
                                serverIdentity.ServerContext
                            };
                            replyMsg = (IMessage)CrossContextChannel.SyncProcessMessageCallback(args);
                        }
                        else
                        {
                            replyMsg = ChannelServices.GetCrossContextChannelSink().SyncProcessMessage(msg);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (serverProcessing != ServerProcessing.OneWay)
                {
                    try
                    {
                        IMessage message2;
                        if (msg == null)
                        {
                            IMessage message = new ErrorMessage();
                            message2 = message;
                        }
                        else
                        {
                            message2 = msg;
                        }
                        IMethodCallMessage mcm = (IMethodCallMessage)message2;
                        replyMsg = new ReturnMessage(e, mcm);
                        if (msg != null)
                        {
                            ((ReturnMessage)replyMsg).SetLogicalCallContext((LogicalCallContext)msg.Properties[Message.CallContextKey]);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            return(serverProcessing);
        }
Пример #14
0
 internal static void IncrementRemoteCalls()
 {
     ChannelServices.IncrementRemoteCalls(1L);
 }
Пример #15
0
        internal static IMessageSink CreateMessageSink(object data)
        {
            string text;

            return(ChannelServices.CreateMessageSink(null, data, out text));
        }