Beispiel #1
0
 public void BeforeSendReply(ref Message reply, object correlationState)
 {
     if (reply.IsFault)
     {
         MessageBuffer buffer = reply.CreateBufferedCopy(Int32.MaxValue);
         var           fault  = MessageFault.CreateFault(buffer.CreateMessage(), Int32.MaxValue);
         if (fault.Code.SubCode.Name == "ActionNotSupported")
         {
             // TODO message id
             reply = DispatcherUtils.CreateErrorMessage(reply.Version, null,
                                                        (int)JsonRpcErrorCodes.MethodNotFound, "Method not found.",
                                                        fault.Reason.GetMatchingTranslation().Text);
         }
         // TODO process other fault codes
     }
 }
        public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
        {
            bool includeDetails = IncludeExceptionDetails();

            object msgId = null;

            if (OperationContext.Current.IncomingMessageProperties.ContainsKey(DispatcherUtils.MessageIdKey))
            {
                msgId = OperationContext.Current.IncomingMessageProperties[DispatcherUtils.MessageIdKey];
            }

            var jsonRpcError = error as JsonRpcException;

            if (jsonRpcError != null)
            {
                fault = DispatcherUtils.CreateErrorMessage(version, msgId, jsonRpcError);
            }
            else
            {
                // TODO: extract exception details from FaultException
                object additionalData;
                var    faultException = error as FaultException;
                if (faultException != null && faultException.GetType().IsGenericType)
                {
                    additionalData = faultException.GetType().GetProperty("Detail").GetValue(faultException, null);
                }
                else
                {
                    additionalData = error;
                }

                // TODO: check error type and set appropriate error code
                fault = DispatcherUtils.CreateErrorMessage(version, msgId,
                                                           (int)JsonRpcErrorCodes.ServerError, error.Message, additionalData);
            }
        }