Exemplo n.º 1
0
 public void DeSerializeMessage()
 {
     var session = Guid.NewGuid().ToString();
     var req = new MessageRequest { Session = session };
     var serializer = new ProtobufObjectSerializer();
     var stream = new MemoryStream();
     serializer.WriteObject(stream, req);
     stream.Position = 0;
     var deserialized = (MessageRequest)serializer.ReadObject(stream, typeof(MessageRequest));
     Assert.AreEqual(session, deserialized.Session);
 }
Exemplo n.º 2
0
 public void SerializeMessage()
 {
     var req = new MessageRequest { Session = Guid.NewGuid().ToString() };
     var serializer = new ProtobufObjectSerializer();
     var stream = new MemoryStream();
     serializer.WriteObject(stream, req);
     Assert.IsTrue(stream.ToArray().Length > 0);
 }
Exemplo n.º 3
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;
        }
Exemplo n.º 4
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;
        }
Exemplo n.º 5
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();
     }
 }
Exemplo n.º 6
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;
 }