Exemple #1
0
            public object Invoke(object target, System.Reflection.MethodInfo method, object[] parameters)
            {
                var arguments = method.GetParameters();
                var argCount  = arguments.Length;
                var args      = new DictionaryWrapper();

                for (int i = 0; i < argCount; i++)
                {
                    args[arguments[i].Name] = parameters[i];
                }


                var operationName = method.Name;

                var req = ServiceRequest.Create(ServiceName, operationName, args);

                if (ServiceDispatcherName.HasValue())
                {
                    req.Arguments.Add(ServiceDispatcher.ServiceDispatcherParameterName, ServiceDispatcherName);
                }

                var resp = ServiceDispatcher.Dispatch(req);

                if (resp.Success)
                {
                    return(resp.Result);
                }
                else
                {
                    throw resp.Exception;
                }
            }
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="serviceName"></param>
        /// <param name="operationName"></param>
        /// <param name="requestArgs"></param>
        /// <returns></returns>
        public static TResult Dispatch <TResult>(string serviceName, string operationName, object requestArgs)
        {
            var req  = ServiceRequest.Create(serviceName, operationName, requestArgs);
            var resp = ServiceDispatcher.Dispatch(req);

            if (resp.Exception != null)
            {
                throw resp.Exception;
            }
            return((TResult)resp.Result);
        }
Exemple #3
0
            public override IMessage Invoke(IMessage message)
            {
                var methodMessage = message as IMethodCallMessage;
                var method        = methodMessage.MethodBase;

                var argCount = methodMessage.ArgCount;
                var args     = new DictionaryWrapper();

                for (int i = 0; i < argCount; i++)
                {
                    args[methodMessage.GetArgName(i)] = methodMessage.GetArg(i);
                }


                var operationName = method.Name;

                var req = ServiceRequest.Create(ServiceName, operationName, args);

                if (ServiceDispatcherName.HasValue())
                {
                    req.Arguments.Add(ServiceDispatcher.ServiceDispatcherParameterName, ServiceDispatcherName);
                }
                try
                {
                    var resp = ServiceDispatcher.Dispatch(req);

                    if (resp.Success)
                    {
                        return(new ReturnMessage(resp.Result, null, 0, methodMessage.LogicalCallContext, methodMessage));
                    }
                    else
                    {
                        return(new ReturnMessage(resp.Exception, methodMessage));
                    }
                }
                catch (Exception ex)
                {
                    return(new ReturnMessage(ex, methodMessage));
                }
            }
        IServiceRequest PopulateModelBinding(IOperationDescriptor operationDesc, IServiceRequest req, IServiceResponse resp)
        {
            if (req.Arguments == null)
            {
                return(req);
            }

            //备份原始请求参数
            req.Context["RawArguments"] = req.Arguments;

            var data   = operationDesc.GetParameterValues(req.Arguments);
            var tmpReq = ServiceRequest.Create(req.ServiceName, req.OperationName, data);

            tmpReq.ValidateRequest = req.ValidateRequest;

            if (tmpReq.Arguments.ContainsKey("AutoCloseServiceContext"))
            {
                tmpReq.Arguments.Remove("AutoCloseServiceContext");
            }
            tmpReq.Context = req.Context;

            return(tmpReq);
        }