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); }
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(); } }
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); }
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); }
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); }
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 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 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; }
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; }
private bool Equals(OperationDispatchBase other) { return _identifier == other._identifier; }