コード例 #1
0
            public override System.Runtime.Remoting.Messaging.IMessage Invoke(System.Runtime.Remoting.Messaging.IMessage msg)
            {
                IMethodCallMessage methodCallMessage = msg as IMethodCallMessage;

                this.callContext = methodCallMessage.LogicalCallContext.Clone() as LogicalCallContext;
                return(new ReturnMessage(null, null, 0, methodCallMessage.LogicalCallContext, methodCallMessage));
            }
コード例 #2
0
ファイル: EntityProxy.cs プロジェクト: mind0n/hive
        public override System.Runtime.Remoting.Messaging.IMessage Invoke(System.Runtime.Remoting.Messaging.IMessage msg)
        {
            IMethodCallMessage mcMsg = msg as IMethodCallMessage;

            if (mcMsg != null)
            {
                ReturnMessage rlt = null;
                if (!string.Equals(mcMsg.MethodName, "Test", StringComparison.OrdinalIgnoreCase))
                {
                    object instance = null;
                    if (Entity == null)
                    {
                        Type type = Type.GetType(mcMsg.TypeName);
                        instance = Activator.CreateInstance(type);
                    }
                    else
                    {
                        instance = Entity;
                    }
                    object returnValueObject = mcMsg.MethodBase.Invoke(instance, null);
                    rlt = new ReturnMessage(returnValueObject, mcMsg.Args, mcMsg.ArgCount, mcMsg.LogicalCallContext, mcMsg);
                }
                else
                {
                    rlt = new ReturnMessage(new ProxyResult(), mcMsg.Args, mcMsg.ArgCount, mcMsg.LogicalCallContext, mcMsg);
                }

                return(rlt);
            }
            return(null);
        }
コード例 #3
0
        public override System.Runtime.Remoting.Messaging.IMessage Invoke(System.Runtime.Remoting.Messaging.IMessage msg)
        {
            IMethodCallMessage call = msg as IMethodCallMessage;

            try
            {
                if (!IsPassThrough(call.MethodBase))
                {
                    if (!IsNestedEngineCall())
                    {
                        if (IsQuery(call.MethodBase))
                        {
                            return(ExecuteQuery(call));
                        }

                        if (IsCommand(call.MethodBase))
                        {
                            return(ExecuteCommand(call));
                        }
                    }
                }
                return(InvokeSystem(call));
            }
            catch (System.Reflection.TargetInvocationException x)
            {
                return(new ReturnMessage(x.InnerException, call));
            }
            catch (Exception x)
            {
                return(new ReturnMessage(x, call));
            }
        }
コード例 #4
0
        /// <summary>
        /// When overridden in a derived class, invokes the method that is specified in the provided <see cref="T:System.Runtime.Remoting.Messaging.IMessage" /> on the remote object that is represented by the current instance.
        /// </summary>
        /// <param name="msg">A <see cref="T:System.Runtime.Remoting.Messaging.IMessage" /> that contains a <see cref="T:System.Collections.IDictionary" /> of information about the method call.</param>
        /// <returns>
        /// The message returned by the invoked method, containing the return value and any out or ref parameters.
        /// </returns>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="Infrastructure" />
        /// </PermissionSet>
        public override System.Runtime.Remoting.Messaging.IMessage Invoke(System.Runtime.Remoting.Messaging.IMessage msg)
        {
            IMethodCallMessage message = msg as IMethodCallMessage;
            MethodInfo         method  = (MethodInfo)message.MethodBase;

            bool doProxy;

            if (lookup.ContainsKey(method))
            {
                doProxy = lookup[method];
            }
            else
            {
                doProxy = proxy.ShouldProxy(method);
                lookup.Add(method, doProxy);
            }

            try
            {
                object result;
                if (doProxy)
                {
                    result = proxy.Invoke(method, target, message.Args, method.ReturnType);
                }
                else
                {
                    result = method.Invoke(target, message.Args);
                }
                return(new ReturnMessage(result, null, 0, null, message));
            }
            catch (Exception ex)
            {
                return(new ReturnMessage(ex, message));
            }
        }
コード例 #5
0
        public override IMessage Invoke(IMessage msg)
        {
            var methodCall = msg as IMethodCallMessage;
            // ReSharper disable once PossibleNullReferenceException
            var methodInfo = methodCall.MethodBase as MethodInfo;

            // ReSharper disable once PossibleNullReferenceException
            var returnValue = _callServer(new RabbitDelegateMessage(methodInfo.Name, methodCall.InArgs));

            return(new ReturnMessage(returnValue, null, 0, methodCall.LogicalCallContext, methodCall));
        }
コード例 #6
0
        public override System.Runtime.Remoting.Messaging.IMessage Invoke(System.Runtime.Remoting.Messaging.IMessage msg)
        {
            IMethodCallMessage methodCallMessage = msg as IMethodCallMessage;
            MethodInfo         methodInfo        = (MethodInfo)methodCallMessage.MethodBase;

            using (var factory = CreateChannelFactory(url))
            {
                object result = methodInfo.Invoke(factory.CreateChannel(), methodCallMessage.InArgs);
                return(new ReturnMessage(result, null, 0, methodCallMessage.LogicalCallContext, methodCallMessage));
            }
        }
コード例 #7
0
        public ServerProcessing ProcessMessage(IServerChannelSinkStack sinkStack, System.Runtime.Remoting.Messaging.IMessage requestMsg, ITransportHeaders requestHeaders, System.IO.Stream requestStream, out System.Runtime.Remoting.Messaging.IMessage responseMsg, out ITransportHeaders responseHeaders, out System.IO.Stream responseStream)
        {
            if (_nextSink != null)
            {
                IPAddress ip = requestHeaders[CommonTransportKeys.IPAddress] as IPAddress;
                CallContext.SetData("ClientIpAddress", ip);
                ServerProcessing spres = _nextSink.ProcessMessage(sinkStack, requestMsg, requestHeaders, requestStream, out responseMsg, out responseHeaders, out responseStream);

                return(spres);
            }
            else
            {
                responseMsg     = null;
                responseHeaders = null;
                responseStream  = null;

                return(new ServerProcessing());
            }
        }
コード例 #8
0
ファイル: ChannelProxy.cs プロジェクト: lazy111/test
        public override System.Runtime.Remoting.Messaging.IMessage Invoke(System.Runtime.Remoting.Messaging.IMessage msg)
        {
            IMethodCallMessage methodCall = (IMethodCallMessage)msg;

            //得到操作名称
            object[] attributes = methodCall.MethodBase.GetCustomAttributes(typeof(OperationContractAttribute), false);
            OperationContractAttribute attribute = attributes[0] as OperationContractAttribute;
            string operationName = string.IsNullOrEmpty(attribute.Name) ? methodCall.MethodName : attribute.Name;

            Message requestMessage = MessageFormatter[operationName].SerializeRequest(this.MessageVersion, methodCall.InArgs);

            EndpointAddress address = new EndpointAddress(this.Address);

            requestMessage.Headers.MessageId = new UniqueId(Guid.NewGuid());
            requestMessage.Headers.ReplyTo   = new EndpointAddress("http://www.w3.org/2005/08/addressing/anonymous");
            address.ApplyTo(requestMessage);

            HttpWebRequest web = (HttpWebRequest)HttpWebRequest.Create(Address);

            web.Method      = "Post";
            web.KeepAlive   = true;
            web.ContentType = "application/soap+xml; charset=utf-8";


            ArraySegment <byte> bytes = this.MessageEncoderFactory.Encoder.WriteMessage(requestMessage, int.MaxValue, BufferManager.CreateBufferManager(long.MaxValue, int.MaxValue));

            web.ContentLength = bytes.Array.Length;
            web.GetRequestStream().Write(bytes.Array, 0, bytes.Array.Length);
            web.GetRequestStream().Close();
            WebResponse response = (WebResponse)web.GetResponse();

            //回复消息进行反列化生成相应的对象,并映射为方法调用的返回值或者ref/out参数
            object[] allArgs = (object[])Array.CreateInstance(typeof(object), methodCall.ArgCount);
            Array.Copy(methodCall.Args, allArgs, methodCall.ArgCount);
            Message responseMessage = this.MessageEncoderFactory.Encoder.ReadMessage(response.GetResponseStream(), int.MaxValue);
            object  result          = this.MessageFormatter[operationName].DeserializeReply(responseMessage, new object[GetRefOutParamterCount(methodCall.MethodBase)]);

            MapRefOutParameter(methodCall.MethodBase, allArgs, new object[GetRefOutParamterCount(methodCall.MethodBase)]);
            return(new ReturnMessage(result, allArgs, allArgs.Length, methodCall.LogicalCallContext, methodCall));
        }
コード例 #9
0
ファイル: AOP.cs プロジェクト: chakian/movie-archive
        public override System.Runtime.Remoting.Messaging.IMessage Invoke(System.Runtime.Remoting.Messaging.IMessage msg)
        {
            object             returnValue   = null;
            IMethodCallMessage methodMessage = ( IMethodCallMessage )msg;
            MethodBase         method        = methodMessage.MethodBase;

            var concernMethod = Joinpoints
                                .Where(
                x =>
                x.PointcutMethod.Name == method.Name &&
                Utils.TypeArrayMatch(x.PointcutMethod.GetParameters( ).Select(p => p.ParameterType).ToArray( ), method.GetParameters( ).Select(p => p.ParameterType).ToArray( ))
                )
                                .Select(x => x.ConcernMethod).FirstOrDefault( );

            if (concernMethod != null)
            {
                var param = concernMethod.IsStatic ? null : Concerns.First(x => x.GetType( ) == concernMethod.DeclaringType);
                returnValue = concernMethod.Invoke(param, methodMessage.Args);
            }
            else
            {
                var targetMethod = Target
                                   .GetType( )
                                   .GetMethods( )
                                   .Where(
                    x =>
                    x.Name == method.Name &&
                    Utils.TypeArrayMatch(x.GetParameters( ).Select(p => p.ParameterType).ToArray( ), method.GetParameters( ).Select(p => p.ParameterType).ToArray( ))
                    )
                                   .FirstOrDefault( );

                var param = targetMethod.IsStatic ? null : Target;

                returnValue = targetMethod.Invoke(param, methodMessage.Args);
            }

            return(new ReturnMessage(returnValue, methodMessage.Args, methodMessage.ArgCount, methodMessage.LogicalCallContext, methodMessage));
        }
コード例 #10
0
 public void AsyncProcessResponse(System.Runtime.Remoting.Channels.IServerResponseChannelSinkStack sinkStack, System.Object state, System.Runtime.Remoting.Messaging.IMessage msg, System.Runtime.Remoting.Channels.ITransportHeaders headers, System.IO.Stream stream)
 {
 }
コード例 #11
0
 public System.IO.Stream GetResponseStream(IServerResponseChannelSinkStack sinkStack, object state, System.Runtime.Remoting.Messaging.IMessage msg, ITransportHeaders headers)
 {
     return(null);
 }
コード例 #12
0
        //---------------------- Implement IServerChannelSink -------------------//

        public void AsyncProcessResponse(IServerResponseChannelSinkStack sinkStack, object state, System.Runtime.Remoting.Messaging.IMessage msg, ITransportHeaders headers, System.IO.Stream stream)
        {
            IPAddress ip = headers[CommonTransportKeys.IPAddress] as IPAddress;

            CallContext.SetData("ClientIpAddress", ip);
            sinkStack.AsyncProcessResponse(msg, headers, stream);
        }
コード例 #13
0
 public override System.Runtime.Remoting.Messaging.IMessage Invoke(System.Runtime.Remoting.Messaging.IMessage msg)
 {
     return(InvokeRemoteCall((IMethodCallMessage)msg, this._target));
 }
コード例 #14
0
 System.IO.Stream IServerChannelSink.GetResponseStream(IServerResponseChannelSinkStack sinkStack, object state, System.Runtime.Remoting.Messaging.IMessage msg, ITransportHeaders headers)
 {
     return(nextSink.GetResponseStream(sinkStack, state, msg, headers));
 }
コード例 #15
0
 public Stream GetRequestStream(System.Runtime.Remoting.Messaging.IMessage msg, System.Runtime.Remoting.Channels.ITransportHeaders headers)
 {
     //not implemented, since only formatter sink need to call this method
     return(null);
 }
コード例 #16
0
ファイル: ClientTransportSink.cs プロジェクト: shubhtr/smuxi
 public Stream GetRequestStream(System.Runtime.Remoting.Messaging.IMessage msg, System.Runtime.Remoting.Channels.ITransportHeaders headers)
 {
     // no direct way to access the stream
     return(null);
 }
コード例 #17
0
 public Stream GetRequestStream(System.Runtime.Remoting.Messaging.IMessage msg, System.Runtime.Remoting.Channels.ITransportHeaders headers)
 {
     return(null);
 }
コード例 #18
0
 ServerProcessing IServerChannelSink.ProcessMessage(IServerChannelSinkStack sinkStack, System.Runtime.Remoting.Messaging.IMessage requestMsg, ITransportHeaders requestHeaders, System.IO.Stream requestStream, out System.Runtime.Remoting.Messaging.IMessage responseMsg, out ITransportHeaders responseHeaders, out System.IO.Stream responseStream)
 {
     if (Application.OpenForms.Count > 0)
     {
         IMessage          outResponseMsg     = null;
         ITransportHeaders outResponseHeaders = null;
         Stream            outResponseStream  = null;
         ServerProcessing  returnValue        = ServerProcessing.Complete;
         Application.OpenForms[0].Invoke(new EventHandler(delegate
         {
             returnValue = nextSink.ProcessMessage(sinkStack, requestMsg, requestHeaders, requestStream, out outResponseMsg, out outResponseHeaders, out outResponseStream);
         }));
         responseMsg     = outResponseMsg;
         responseHeaders = outResponseHeaders;
         responseStream  = outResponseStream;
         return(returnValue);
     }
     else
     {
         return(nextSink.ProcessMessage(sinkStack, requestMsg, requestHeaders, requestStream, out responseMsg, out responseHeaders, out responseStream));
     }
 }
コード例 #19
0
        public override System.Runtime.Remoting.Messaging.IMessage Invoke(System.Runtime.Remoting.Messaging.IMessage msg)
        {
            IMethodCallMessage methodCall = (IMethodCallMessage)msg;
            MethodInfo         methodInfo = (MethodInfo)methodCall.MethodBase;

            ParameterInfo[]   parameters = methodInfo.GetParameters();
            SqlCommand        command    = getSqlCommand(methodInfo);
            bool              hasOutput  = false;
            SpmSharedItemPool itemPool   = null;
            int itemPoolArgIndex         = -1;

            for (int i = 0; i < parameters.Length; i++)
            {
                if (parameters[i].ParameterType.Equals(typeof(SpmSharedItemPool)))
                {
                    if (itemPoolArgIndex < 0)
                    {
                        itemPoolArgIndex = i;
                        itemPool         = (SpmSharedItemPool)methodCall.Args[i];
                    }
                    else
                    {
                        throw new ArgumentException("SpmItemPool в параметрах встречается более одного раза");
                    }
                }
                else
                {
                    hasOutput |= command.Parameters.Add(
                        getSqlParameter(parameters[i], methodCall.Args[i])).Direction != ParameterDirection.Input;
                }
            }
            object result     = null;
            bool   mustClosed = false;

            try
            {
                command.Connection =
                    new SqlConnection(this.connectionString, this.credential);
                mustClosed = true;
                command.Connection.Open();
                result = executeCommand(methodInfo, command, ref mustClosed, itemPool);
            }
            catch (Exception ex)
            {
                return(new ReturnMessage(ex, msg as IMethodCallMessage));
            }
            finally
            {
                if (mustClosed)
                {
                    command.Connection.Close();
                }
                command.Dispose();
            }
            object[] outArgs = null;
            if (hasOutput)
            {
                outArgs = new object[methodCall.ArgCount];
                int currCount = itemPoolArgIndex < 0 ? outArgs.Length : itemPoolArgIndex;
                for (int i = 0; i < currCount; i++)
                {
                    outArgs[i] = parameters[i].ParameterType.IsByRef ? command.Parameters[i].Value : null;
                }
                for (int i = ++currCount; i < outArgs.Length; i++)
                {
                    outArgs[i] = parameters[i - 1].ParameterType.IsByRef ? command.Parameters[i - 1].Value : null;
                }
            }
            return(new ReturnMessage(result, outArgs, outArgs == null ? 0 : outArgs.Length, methodCall.LogicalCallContext, methodCall));
        }
コード例 #20
0
 void IServerChannelSink.AsyncProcessResponse(IServerResponseChannelSinkStack sinkStack, object state, System.Runtime.Remoting.Messaging.IMessage msg, ITransportHeaders headers, System.IO.Stream stream)
 {
     nextSink.AsyncProcessResponse(sinkStack, state, msg, headers, stream);
 }