Esempio n. 1
0
        private Message invokeContract(OperationDispatchBase operation, MessageRequest request)
        {
            var args = deserializeMessageArguments(request, operation);

            if (operation is AsyncOperationDispatch)
            {
                args.Add(null); //AsyncCallback
                args.Add(null); //object asyncState
            }
            var response = new Message();

            try
            {
                var result = invokeServerMethod(operation, args);
                enrichResponseWithReturn(operation, result, response);
            }
            catch (Exception ex)
            {
                response = makeFault(ex, response);
            }
            finally
            {
                OperationContext.Current = _noOp;
            }

            return(response);
        }
Esempio n. 2
0
 private void enrichResponseWithReturn(OperationDispatchBase operation, object result, Message response)
 {
     if (operation.MethodInfo.ReturnType != typeof(void) && operation.GetType() != typeof(AsyncOperationDispatch))
     {
         var stream = new MemoryStream();
         _endpoint._binding.Serializer.WriteObject(stream, result);
         response.Data = stream.ToArray();
     }
 }
Esempio n. 3
0
        private List <object> deserializeMessageArguments(MessageRequest request, OperationDispatchBase operation)
        {
            var args = new List <object>(operation.Params.Count);

            for (int i = 0; i < operation.Params.Count; i++)
            {
                RpcParamData pData = request.Data[i];
                var          map   = operation.Params[pData.Identifier];
                var          type  = map.Info.ParameterType;
                var          obj   = _endpoint._binding.Serializer.ReadObject(new MemoryStream(pData.Data), type);
                args.Add(obj);
            }
            return(args);
        }
Esempio n. 4
0
 private object invokeViaReflection(OperationDispatchBase operation, List <object> args)
 {
     try
     {
         return(operation.MethodInfo.Invoke(_singletonService, BindingFlags.Public, null, args.ToArray(), null));
     }
     catch (TargetInvocationException ex)
     {
         if (ex.InnerException != null)
         {
             throw ex.InnerException; //invoked method throw error which we rethrow
         }
         throw;                       // usually when failed to find method on CLR object
     }
 }
        private static DispatchTable createOperations(MethodInfo[] ops)
        {
            Contract.Ensures(Contract.Result <DispatchTable>().IdToOperation.Count == Contract.Result <DispatchTable>().TokenToOperation.Count);
            var operations = new DispatchTable();

            for (int orderNumber = 0; orderNumber < ops.Length; orderNumber++)
            {
                var methodInfo = ops[orderNumber];
                var identifier = createIdentifier(methodInfo, orderNumber);
                OperationDispatchBase operation = create(methodInfo, identifier);
                operations.IdToOperation[identifier] = operation;
                operations.TokenToOperation[methodInfo.MetadataToken] = operation;
            }
            return(operations);
        }
Esempio n. 6
0
        private object invokeServerMethod(OperationDispatchBase operation, List <object> args)
        {
            object result = null;

            if (_syncContext != null)
            {
                _syncContext.Send(
                    _ =>
                    result = invokeViaReflection(operation, args),
                    null);
            }
            else
            {
                result = invokeViaReflection(operation, args);
            }
            return(result);
        }
 private bool Equals(OperationDispatchBase other)
 {
     return(_identifier == other._identifier);
 }
Esempio n. 8
0
 private object invokeViaReflection(OperationDispatchBase operation, List<object> args)
 {
     try
     {
         return operation.MethodInfo.Invoke(_singletonService, BindingFlags.Public, null, args.ToArray(), null);
     }
     catch (TargetInvocationException ex)
     {
         if (ex.InnerException != null)
         {
             throw ex.InnerException; //invoked method throw error which we rethrow
         }
         throw; // usually when failed to find method on CLR object
     }
 }
Esempio n. 9
0
 private object invokeServerMethod(OperationDispatchBase operation, List<object> args)
 {
     object result = null;
     if (_syncContext != null)
     {
         _syncContext.Send(
             _ =>
            result = invokeViaReflection(operation, args),
             null);
     }
     else
     {
         result = invokeViaReflection(operation, args);
     }
     return result;
 }
Esempio n. 10
0
        private Message invokeContract(OperationDispatchBase operation, MessageRequest request)
        {
            var args = deserializeMessageArguments(request, operation);
            if (operation is AsyncOperationDispatch)
            {
                args.Add(null);//AsyncCallback
                args.Add(null);//object asyncState
            }
            var response = new Message();
            try
            {
                var result = invokeServerMethod(operation, args);
                enrichResponseWithReturn(operation, result, response);
            }
            catch (Exception ex)
            {
                response = makeFault(ex, response);
            }
            finally
            {
                OperationContext.Current = _noOp;
            }

            return response;
        }
Esempio n. 11
0
 private void enrichResponseWithReturn(OperationDispatchBase operation, object result, Message response)
 {
     if (operation.MethodInfo.ReturnType != typeof(void) && operation.GetType() != typeof(AsyncOperationDispatch))
     {
         var stream = new MemoryStream();
         _endpoint._binding.Serializer.WriteObject(stream, result);
         response.Data = stream.ToArray();
     }
 }
Esempio n. 12
0
 private List<object> deserializeMessageArguments(MessageRequest request, OperationDispatchBase operation)
 {
     var args = new List<object>(operation.Params.Count);
     for (int i = 0; i < operation.Params.Count; i++)
     {
         RpcParamData pData = request.Data[i];
         var map = operation.Params[pData.Identifier];
         var type = map.Info.ParameterType;
         var obj = _endpoint._binding.Serializer.ReadObject(new MemoryStream(pData.Data), type);
         args.Add(obj);
     }
     return args;
 }
Esempio n. 13
0
 private bool Equals(OperationDispatchBase other)
 {
     return _identifier == other._identifier;
 }