public Future <Message> ExecuteOperation(Message inMsg, Action <Message> onResult, Action <ushort, string> onError)
        {
            _requestId++;
            inMsg.AttachHeader(new OperationHeader(_requestId, OperationType.Request));
            Channel.Send(inMsg);
            MsgFactory.Free(inMsg);
            var future = new Future <Message>(onResult, onError);

            _pendingOperation.Add(_requestId, future);
            return(future);
        }
        public void OnNetData(BinaryReader reader)
        {
            Message msg = MsgFactory.Deserialize(reader);


            var opHeader = msg.GetHeader <OperationHeader>();

            if (opHeader != null && opHeader.Type == OperationType.Reply)
            {
                Future <Message> future;
                if (_pendingOperation.TryGetValue(opHeader.RequestId, out future))
                {
                    if (msg is InvalidOperation)
                    {
                        var inv = msg as InvalidOperation;
                        future.SetError(inv.ErrorCode, inv.DebugDescription);
                    }
                    else
                    {
                        future.SetResult(msg);
                    }
                    _pendingOperation.Remove(opHeader.RequestId);
                }
            }
            else
            {
                NetContractDescription contractDesc = Dispatcher.GetContractForMessage(msg.Id);

                object handler;
                if (_handlersByNetContractId.TryGetValue(contractDesc.TypeId, out handler))
                {
                    Dispatcher.DispatchOneWay(handler, msg);
                }
            }

            MsgFactory.Free(msg);
        }
 public void ExecuteOneWayOperation(Message inMsg)
 {
     Channel.Send(inMsg);
     MsgFactory.Free(inMsg);
 }