Esempio n. 1
0
 private void applyReplyProcessing(Message reply)
 {
     foreach (IClientMessageInspector inspector in _router.MessageInspectors)
     {
         inspector.AfterReceiveReply(ref reply, null);
     }
     if (reply.Fault != null)
     {
         throw translateFault(reply.Fault);
     }
 }
Esempio n. 2
0
        private Message makeFault(Exception ex, Message response)
        {
            var error = ex.ToString();
            var detail = new MemoryStream();
            _encoder.WriteObject(detail, error);
            //TODO: make fault with details only in case of IncludeExceptionDetailsInFaults
            response.Fault = new FaultData()
                {
                    Code = ex.GetType().GUID.ToString(),
                    Reason = ex.Message,
                    Detail = detail.ToArray(),
                    Name = ex.GetType().FullName,
                    Node = _endpoint._address
                };

            foreach (var errorHandler in _channelDispatcher.ErrorHandlers)
            {
                if (errorHandler.HandleError(ex))
                {
                    errorHandler.ProvideFault(ex, MessageVersion.WcfProtoRpc1, ref response);
                }
            }
            return response;
        }
Esempio n. 3
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. 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;
        }
Esempio n. 5
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();
     }
 }