Esempio n. 1
0
 public byte[] Invoke(IRpcCallInfo call, Type contractType, byte[] arg)
 {
     var messageRequest = (MessageRequest)_encoder.ReadObject(new MemoryStream(arg), typeof(MessageRequest));
     Message response = invokeContract(call, messageRequest, contractType);
     var stream = new MemoryStream();
     _encoder.WriteObject(stream, response);
     return stream.ToArray();
 }
Esempio n. 2
0
        public byte[] Invoke(IRpcCallInfo call, Type contractType, byte[] arg)
        {
            var     messageRequest = (MessageRequest)_encoder.ReadObject(new MemoryStream(arg), typeof(MessageRequest));
            Message response       = invokeContract(call, messageRequest, contractType);
            var     stream         = new MemoryStream();

            _encoder.WriteObject(stream, response);
            return(stream.ToArray());
        }
Esempio n. 3
0
        /// <summary>
        /// Can be over-ridden in a derived class to handle the incomming RPC request, or you can
        /// subscribe to the OnExecute event.
        /// </summary>
        public virtual byte[] Execute(IRpcCallInfo call, byte[] input)
        {
            RpcExecuteHandler proc = _handler;

            if (proc != null)
            {
                return(proc(call, input));
            }
            return(null);
        }
Esempio n. 4
0
        private Message invokeContract(IRpcCallInfo call, MessageRequest request, Type contractType)
        {
            OperationDispatchBase operation;
            bool operationExists = _operations.IdToOperation.TryGetValue(request.Operation, out operation);

            if (!operationExists)
            {
                var error        = new ActionNotSupportedException(string.Format("Server endpoint {0} with contract {1} does not supports operation with id = {2}. Check that client and server use the same version of contract and binding. ", _endpoint._address, contractType, request.Operation));
                var faultMessage = new Message();
                faultMessage = makeFault(error, faultMessage);
                return(faultMessage);
            }
            OperationContext operationContext = SetupOperationConext(call, request, contractType);
            Func <Message>   invokeAction     = () =>
            {
                OperationContext.Current = operationContext;
                if (_concurrency == ConcurrencyMode.Single)
                {
                    lock (this)
                    {
                        return(invokeContract(operation, request));
                    }
                }
                return(invokeContract(operation, request));
            };

            if (operation.Operation.IsOneWay)
            {
                Task task = Tasks.Factory.StartNew(invokeAction);
                task.ContinueWith(x => RpcTrace.Error(x.Exception), TaskContinuationOptions.OnlyOnFaulted);
                return(new Message());
            }
            else
            {
                return(invokeAction());
            }
        }
Esempio n. 5
0
        private OperationContext SetupOperationConext(IRpcCallInfo call, MessageRequest request, Type contractType)
        {
            var operationContext = new OperationContext {
                SessionId = request.Session
            };

            if (request.Session != null)
            {
                if (_duplex)
                {
                    lock (_clients)
                    {
                        RpcCallbackChannelFactory channelFactory = null;
                        bool contains = _clients.TryGetValue(request.Session, out channelFactory);
                        if (!contains)
                        {
                            var contract = AttributesReader.GetServiceContract(contractType);
                            channelFactory = new RpcCallbackChannelFactory(_endpoint._binding,
                                                                           contract.CallbackContract, new Guid(request.Session),
                                                                           true);
                            _clients[request.Session] = channelFactory;
                        }
                        var callbackBindingInfo = EndpointMapper.WcfToRpc(_endpoint._address);
                        if (!call.IsClientLocal)
                        {
                            //BUG: callbacks accross network does not work
                            //callbackAddress.NetworkAddr =  call.ClientAddress
                        }

                        callbackBindingInfo.EndPoint += request.Session.Replace("-", "");
                        operationContext.SetGetter(_clients[request.Session], EndpointMapper.RpcToWcf(callbackBindingInfo));
                    }
                }
            }
            return(operationContext);
        }
Esempio n. 6
0
        private OperationContext SetupOperationConext(IRpcCallInfo call, MessageRequest request, Type contractType)
        {
            var operationContext = new OperationContext { SessionId = request.Session };

            if (request.Session != null)
            {
                if (_duplex)
                {
                    lock (_clients)
                    {
                        RpcCallbackChannelFactory channelFactory = null;
                        bool contains = _clients.TryGetValue(request.Session, out channelFactory);
                        if (!contains)
                        {
                            var contract = AttributesReader.GetServiceContract(contractType);
                            channelFactory = new RpcCallbackChannelFactory(_endpoint._binding,
                                                                           contract.CallbackContract, new Guid(request.Session),
                                                                           true);
                            _clients[request.Session] = channelFactory;
                        }
                        var callbackBindingInfo = EndpointMapper.WcfToRpc(_endpoint._address);
                        if (!call.IsClientLocal)
                        {
                            //BUG: callbacks accross network does not work
                            //callbackAddress.NetworkAddr =  call.ClientAddress
                        }

                        callbackBindingInfo.EndPoint += request.Session.Replace("-", "");
                        operationContext.SetGetter(_clients[request.Session], EndpointMapper.RpcToWcf(callbackBindingInfo));
                    }
                }
            }
            return operationContext;
        }
Esempio n. 7
0
 private Message invokeContract(IRpcCallInfo call, MessageRequest request, Type contractType)
 {
     OperationDispatchBase operation;
     bool operationExists = _operations.IdToOperation.TryGetValue(request.Operation, out operation);
     if (!operationExists)
     {
         var error = new ActionNotSupportedException(string.Format("Server endpoint {0} with contract {1} does not supports operation with id = {2}. Check that client and server use the same version of contract and binding. ", _endpoint._address, contractType, request.Operation));
         var faultMessage = new Message();
         faultMessage = makeFault(error, faultMessage);
         return faultMessage;
     }
     OperationContext operationContext = SetupOperationConext(call, request, contractType);
     Func<Message> invokeAction = () =>
         {
             OperationContext.Current = operationContext;
             if (_concurrency == ConcurrencyMode.Single)
             {
                 lock (this)
                 {
                     return invokeContract(operation, request);
                 }
             }
             return invokeContract(operation, request);
         };
     if (operation.Operation.IsOneWay)
     {
         Task task = Tasks.Factory.StartNew(invokeAction);
         task.ContinueWith(x => RpcTrace.Error(x.Exception), TaskContinuationOptions.OnlyOnFaulted);
         return new Message();
     }
     else
     {
         return invokeAction();
     }
 }
Esempio n. 8
0
 static byte[] api_OnExecute(IRpcCallInfo client, byte[] input)
 {
     byte[] resp = new byte[input.Length * 10];
     return resp;
 }
Esempio n. 9
0
 static byte[] api_OnExecute(IRpcCallInfo client, byte[] input)
 {
     byte[] resp = new byte[input.Length * 10];
     return(resp);
 }
Esempio n. 10
0
 /// <summary>
 /// Can be over-ridden in a derived class to handle the incomming RPC request, or you can
 /// subscribe to the OnExecute event.
 /// </summary>
 public virtual byte[] Execute(IRpcCallInfo call, byte[] input)
 {
     RpcExecuteHandler proc = _handler;
     if (proc != null)
     {
         return proc(call, input);
     }
     return null;
 }