Beispiel #1
0
        public void ProvideFault(Exception error, MessageVersion version, ref Message msg)
        {
            if (error is FaultException <ErrorServicioRespuesta> )
            {
                return;
            }

            ErrorServicioRespuesta faultDetail = ErrorBuilder.ConstruirError(error);

            if (faultDetail == null)
            {
                return;
            }

            Type faultType =
                typeof(FaultException <>).MakeGenericType(faultDetail.GetType());

            var       faultReason = new FaultReason(faultDetail.Mensaje);
            FaultCode faultCode   = FaultCode.CreateReceiverFaultCode(new FaultCode(faultDetail.Codigo));

            var faultException =
                (FaultException)Activator.CreateInstance(faultType, faultDetail, faultReason, faultCode);

            MessageFault faultMessage = faultException.CreateMessageFault();

            msg = Message.CreateMessage(version, faultMessage, faultException.Action);
        }
 private void ProvideFaultOfLastResort(Exception error, ref ErrorHandlerFaultInfo faultInfo)
 {
     if (faultInfo.Fault == null)
     {
         MessageFault fault;
         FaultCode    subCode = new FaultCode("InternalServiceFault", "http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher");
         subCode = FaultCode.CreateReceiverFaultCode(subCode);
         string action = "http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher/fault";
         if (this.debug)
         {
             faultInfo.DefaultFaultAction = action;
             fault = MessageFault.CreateFault(subCode, new FaultReason(error.Message), new ExceptionDetail(error));
         }
         else
         {
             string text = this.isOnServer ? System.ServiceModel.SR.GetString("SFxInternalServerError") : System.ServiceModel.SR.GetString("SFxInternalCallbackError");
             fault = MessageFault.CreateFault(subCode, new FaultReason(text));
         }
         faultInfo.IsConsideredUnhandled = true;
         faultInfo.Fault = Message.CreateMessage(this.messageVersion, fault, action);
     }
     else if (error != null)
     {
         FaultException exception = error as FaultException;
         if ((((exception != null) && (exception.Fault != null)) && ((exception.Fault.Code != null) && (exception.Fault.Code.SubCode != null))) && ((string.Compare(exception.Fault.Code.SubCode.Namespace, "http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher", StringComparison.Ordinal) == 0) && (string.Compare(exception.Fault.Code.SubCode.Name, "InternalServiceFault", StringComparison.Ordinal) == 0)))
         {
             faultInfo.IsConsideredUnhandled = true;
         }
     }
 }
Beispiel #3
0
        public void OnPremiseResponseReceiver_ReceiveResponse_FaultMessage()
        {
            MockDispatcher dispatcher = new MockDispatcher();

            AzureResponseReceiver receiver = new AzureResponseReceiver(dispatcher);

            Message emptyMessage = Message.CreateMessage(MessageVersion.Default, string.Empty);

            MessageFault fault = MessageFault.CreateFault(FaultCode.CreateReceiverFaultCode("Error", Constant.HpcHeaderNS), string.Empty);

            DispatchData data = new DispatchData("1", 0, "1")
            {
                BrokerQueueItem = new BrokerQueueItem(null, emptyMessage, null),

                Client = new MockClient()
                {
                    Response = Message.CreateMessage(MessageVersion.Default, fault, string.Empty)
                }
            };

            receiver.ReceiveResponse(data);

            Assert.AreEqual(data.Exception, null, "Exception is not expected to happen in ReceiveResponse method.");

            Assert.AreEqual(data.ReplyMessage.IsFault, true, "Expected to receive fault message ReceiveResponse method.");
        }
Beispiel #4
0
        private MessageFault BuildFault(Exception error)
        {
            ServiceExceptionDetail exceptionDetail = new ServiceExceptionDetail(error);
            FaultCode code = FaultCode.CreateReceiverFaultCode(ServiceExceptionDetail.FaultSubCodeName, ServiceExceptionDetail.FaultSubCodeNamespace);

            return(MessageFault.CreateFault(code, new FaultReason(error.Message), exceptionDetail));
        }
Beispiel #5
0
 private void ProvideFaultOfLastResort(Exception error, ref ErrorHandlerFaultInfo faultInfo)
 {
     if (faultInfo.Fault == null)
     {
         FaultCode code = new FaultCode(FaultCodeConstants.Codes.InternalServiceFault, FaultCodeConstants.Namespaces.NetDispatch);
         code = FaultCode.CreateReceiverFaultCode(code);
         string       action = FaultCodeConstants.Actions.NetDispatcher;
         MessageFault fault;
         if (_debug)
         {
             faultInfo.DefaultFaultAction = action;
             fault = MessageFault.CreateFault(code, new FaultReason(error.Message), new ExceptionDetail(error));
         }
         else
         {
             string reason = _isOnServer ? SRServiceModel.SFxInternalServerError : SRServiceModel.SFxInternalCallbackError;
             fault = MessageFault.CreateFault(code, new FaultReason(reason));
         }
         faultInfo.IsConsideredUnhandled = true;
         faultInfo.Fault = Message.CreateMessage(_messageVersion, fault, action);
     }
     //if this is an InternalServiceFault coming from another service dispatcher we should treat it as unhandled so that the channels are cleaned up
     else if (error != null)
     {
         FaultException e = error as FaultException;
         if (e != null && e.Fault != null && e.Fault.Code != null && e.Fault.Code.SubCode != null &&
             string.Compare(e.Fault.Code.SubCode.Namespace, FaultCodeConstants.Namespaces.NetDispatch, StringComparison.Ordinal) == 0 &&
             string.Compare(e.Fault.Code.SubCode.Name, FaultCodeConstants.Codes.InternalServiceFault, StringComparison.Ordinal) == 0)
         {
             faultInfo.IsConsideredUnhandled = true;
         }
     }
 }
        void HandleFault(
            Exception error,
            ref Message fault,
            Guid handlingInstanceId,
            FaultContractWrapperException faultContractWrapper = null)
        {
            if (fault == null)
            {
                throw new ArgumentNullException(nameof(fault));
            }

            if (_wcfContext.HasWebOperationContext)
            {
                BuildHttpResponseMessage(
                    $"An error has occurred while consuming this service. Please contact your administrator for more information. Error ID: {GetHandlingInstanceId(error, handlingInstanceId)}",
                    fault.Headers.Action,
                    HttpStatusCode.InternalServerError,
                    ref fault);
            }
            else
            {
                fault = Message.CreateMessage(
                    fault.Version,
                    new FaultException(
                        new FaultReason(
                            new FaultReasonText($"An error has occurred while consuming this service. Please contact your administrator for more information. Error ID: {GetHandlingInstanceId(error, handlingInstanceId)}")),
                        FaultCode.CreateReceiverFaultCode(
                            SoapException.ServerFaultCode.Name,
                            SoapException.ServerFaultCode.Namespace))
                    .CreateMessageFault(),
                    _wcfContext.GetFaultedAction(faultContractWrapper?.FaultContract?.GetType()) ?? fault.Headers.Action);
            }
        }
        private static Message CreateCSRefusedFault(MessageVersion messageVersion, ReliableMessagingVersion reliableMessagingVersion, bool isSenderFault, FaultCode subCode, string reason)
        {
            FaultCode code;

            if (messageVersion.Envelope == EnvelopeVersion.Soap11)
            {
                code = new FaultCode("CreateSequenceRefused", WsrmIndex.GetNamespaceString(reliableMessagingVersion));
            }
            else
            {
                if (messageVersion.Envelope != EnvelopeVersion.Soap12)
                {
                    throw Fx.AssertAndThrow("Unsupported version.");
                }
                if (subCode == null)
                {
                    subCode = new FaultCode("CreateSequenceRefused", WsrmIndex.GetNamespaceString(reliableMessagingVersion), subCode);
                }
                if (isSenderFault)
                {
                    code = FaultCode.CreateSenderFaultCode(subCode);
                }
                else
                {
                    code = FaultCode.CreateReceiverFaultCode(subCode);
                }
            }
            FaultReason  reason2           = new FaultReason(System.ServiceModel.SR.GetString("CSRefused", new object[] { reason }), CultureInfo.CurrentCulture);
            MessageFault fault             = MessageFault.CreateFault(code, reason2);
            string       faultActionString = WsrmIndex.GetFaultActionString(messageVersion.Addressing, reliableMessagingVersion);

            return(Message.CreateMessage(messageVersion, fault, faultActionString));
        }
Beispiel #8
0
 void ReportReceiverFault(string message, string faultCodeName)
 {
     throw new FaultException(
               new FaultReason(new FaultReasonText(message, "en")),
               FaultCode.CreateReceiverFaultCode(faultCodeName,
                                                 Constants.SERVICE_NAMESPACE));
 }
Beispiel #9
0
        private MessageFault BuildFault(Exception error)
        {
            var exceptionDetail = new FaultMessage(error);
            var code            = FaultCode.CreateReceiverFaultCode(FaultMessage.FaultSubCodeName,
                                                                    FaultMessage.FaultSubCodeNamespace);

            return(MessageFault.CreateFault(code, new FaultReason(error.Message), exceptionDetail));
        }
Beispiel #10
0
        private Message BuildFaultMessage(string action)
        {
            var fault = MessageFault.CreateFault(
                FaultCode.CreateReceiverFaultCode("e1", "http://tempuri.org"),
                "There was an error processing the message");

            return(Message.CreateMessage(MessageVersion.Default, fault, action));
        }
Beispiel #11
0
        private static MessageFault CreateSoapFault(string faultCode, string faultCodeNameSpace, string faultString)
        {
            // xmlLang in FaultReasonText is set to "". This results in the 'lang' atribute not being part of the faultstring element. The attribute is not mentioned in the SOAP 1.1 specification and hence it is removed.
            var messageFault = MessageFault.CreateFault(FaultCode.CreateReceiverFaultCode(faultCode, faultCodeNameSpace),
                                                        new FaultReason(new FaultReasonText(faultString, "")));

            return(messageFault);
        }
Beispiel #12
0
        /// <summary>
        /// Build fault message
        /// </summary>
        /// <param name="messageId">indicating the message id</param>
        /// <param name="ex">indicating the exception</param>
        /// <returns>returns the fault message</returns>
        private Message BuildFaultMessage(UniqueId messageId, Exception ex)
        {
            MessageFault fault        = MessageFault.CreateFault(FaultCode.CreateReceiverFaultCode("FailProcessRequest", "http://tempuri.org"), String.Format("Failed to process request: {0}", ex));
            Message      faultMessage = Message.CreateMessage(MessageVersion.Default, fault, "http://tempuri.org/FailProcessRequest");

            faultMessage.Headers.RelatesTo = messageId;
            return(faultMessage);
        }
Beispiel #13
0
            public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
            {
                HttpResponseMessageProperty responseProperty;

                if (fault == null)
                {
                    FaultCode code = new FaultCode(FaultCodeConstants.Codes.InternalServiceFault, FaultCodeConstants.Namespaces.NetDispatch);
                    code = FaultCode.CreateReceiverFaultCode(code);
                    string action = FaultCodeConstants.Actions.NetDispatcher;

                    MessageFault innerFault;
                    innerFault = MessageFault.CreateFault(code, new FaultReason(error.Message, CultureInfo.CurrentCulture), new ExceptionDetail(error));
                    fault      = Message.CreateMessage(version, action, new JsonFaultBodyWriter(innerFault, this.includeExceptionDetailInFaults));

                    responseProperty = new HttpResponseMessageProperty();
                    fault.Properties.Add(HttpResponseMessageProperty.Name, responseProperty);
                }
                else
                {
                    MessageFault innerFault = MessageFault.CreateFault(fault, TransportDefaults.MaxFaultSize);
                    Message      newMessage = Message.CreateMessage(version, fault.Headers.Action, new JsonFaultBodyWriter(innerFault, this.includeExceptionDetailInFaults));
                    newMessage.Headers.To = fault.Headers.To;
                    newMessage.Properties.CopyProperties(fault.Properties);

                    object property = null;
                    if (newMessage.Properties.TryGetValue(HttpResponseMessageProperty.Name, out property))
                    {
                        responseProperty = (HttpResponseMessageProperty)property;
                    }
                    else
                    {
                        responseProperty = new HttpResponseMessageProperty();
                        newMessage.Properties.Add(HttpResponseMessageProperty.Name, responseProperty);
                    }

                    fault.Close();
                    fault = newMessage;
                }
                responseProperty.Headers.Add(HttpResponseHeader.ContentType, outgoingContentType);
                responseProperty.Headers.Add(JsonGlobals.jsonerrorString, JsonGlobals.trueString);
                responseProperty.StatusCode = System.Net.HttpStatusCode.InternalServerError;

                object bodyFormatPropertyObject;

                if (fault.Properties.TryGetValue(WebBodyFormatMessageProperty.Name, out bodyFormatPropertyObject))
                {
                    WebBodyFormatMessageProperty bodyFormatProperty = bodyFormatPropertyObject as WebBodyFormatMessageProperty;
                    if ((bodyFormatProperty == null) ||
                        (bodyFormatProperty.Format != WebContentFormat.Json))
                    {
                        fault.Properties[WebBodyFormatMessageProperty.Name] = WebBodyFormatMessageProperty.JsonProperty;
                    }
                }
                else
                {
                    fault.Properties.Add(WebBodyFormatMessageProperty.Name, WebBodyFormatMessageProperty.JsonProperty);
                }
            }
Beispiel #14
0
        void OnWorkflowTerminated(object sender, WorkflowTerminatedEventArgs e)
        {
            Message message =
                Message.CreateMessage(version, FaultCode.CreateReceiverFaultCode(new FaultCode("wf")),
                                      "The workflow aborted unexpectedly",
                                      "http://Microsoft.ServiceModel.Samples/EchoFault");

            callback.EchoFault(message); callback.EchoFault(message);
        }
Beispiel #15
0
        /// <summary>
        /// 截获从Client端发送的消息转发到目标终结点并获得返回值给Client端
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public Message ProcessMessage(Message requestMessage)
        {
            try
            {
                begintime();
                IRouterService  proxy = null;
                HeaderParameter para  = HeaderOperater.GetHeaderValue(requestMessage);

                if (RouterServerManage.routerDic.ContainsKey(para.routerid))
                {
                    proxy = RouterServerManage.routerDic[para.routerid];
                    para.replyidentify = RouterServerManage.headParaDic[para.routerid].replyidentify;
                }
                else
                {
                    //Binding binding = null;
                    EndpointAddress endpointAddress = null;
                    Uri             touri           = null;
                    para = RouterServerManage.AddClient(requestMessage, para, out endpointAddress, out touri);
                    requestMessage.Headers.To = touri;

                    IDuplexRouterCallback callback = OperationContext.Current.GetCallbackChannel <IDuplexRouterCallback>();
                    NetTcpBinding         tbinding = new NetTcpBinding("NetTcpBinding_WCFHandlerService");
                    DuplexChannelFactory <IRouterService> factory = new DuplexChannelFactory <IRouterService>(new InstanceContext(new DuplexRouterCallback(callback)), tbinding, endpointAddress);
                    proxy = factory.CreateChannel();

                    //缓存会话
                    RouterServerManage.routerDic.Add(para.routerid, proxy);
                    RouterServerManage.headParaDic.Add(para.routerid, para);
                }

                Message responseMessage = null;
                HeaderOperater.AddMessageHeader(requestMessage, para);//增加自定义消息头
                responseMessage = proxy.ProcessMessage(requestMessage);

                if (para.cmd == "Quit")
                {
                    //关闭连接释放缓存会话
                    RouterServerManage.RemoveClient(para);
                }

                double outtime = endtime();
                // 请求消息记录
                if (WcfServerManage.IsDebug)
                {
                    RouterServerManage.hostwcfMsg(Color.Black, DateTime.Now, String.Format("路由请求消息发送(耗时[" + outtime + "]):  {0}", requestMessage.Headers.Action));
                }


                return(responseMessage);
            }
            catch (Exception e)
            {
                return(Message.CreateMessage(requestMessage.Version, FaultCode.CreateReceiverFaultCode("error", RouterServerManage.ns), e.Message, requestMessage.Headers.Action));
            }
        }
Beispiel #16
0
        internal static FaultException CreateDispatchFaultException()
        {
            FaultCode code = new FaultCode(FaultCodeConstants.Codes.InternalServiceFault, FaultCodeConstants.Namespaces.NetDispatch);

            code = FaultCode.CreateReceiverFaultCode(code);
            MessageFault dispatchFault = MessageFault.CreateFault(code,
                                                                  new FaultReason(new FaultReasonText(SR.InternalServerError, CultureInfo.CurrentCulture)));

            return(new FaultException(dispatchFault, FaultCodeConstants.Actions.NetDispatcher));
        }
Beispiel #17
0
        private FaultException GetFaultException(string faultReason, string faultCode)
        {
            FaultException faultException =
                new FaultException(
                    new FaultReason(faultReason),
                    FaultCode.CreateReceiverFaultCode(faultCode,
                                                      SoapException.ServerFaultCode.Namespace));

            return(faultException);
        }
Beispiel #18
0
        /// <summary>Creates a fault message from the specified exception.</summary>
        /// <param name="error">The exception that has been raised.</param>
        /// <param name="version">The SOAP version of the message.</param>
        /// <param name="fault">The fault message that is returned to the client.</param>
        public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
        {
            var aex = error as AggregateException;

            if (aex != null)
            {
                if (aex.InnerExceptions.Count > 1)
                {
                    error = new OwsException(OwsExceptionCode.NoApplicableCode, _Reason, error);
                }
                else
                {
                    error = aex.InnerExceptions[0];
                }
            }

            var fex = error as FaultException;

            if (fex == null)
            {
                if (error is NotImplementedException)
                {
                    error = new OwsException(OwsExceptionCode.OperationNotSupported, _Reason, error);
                }

                var oex = error as OwsException;
                if (oex != null)
                {
                    // [OGC 06-121r9, §8.6]
                    var status = HttpStatusCode.InternalServerError;
                    switch (oex.Code)
                    {
                    case OwsExceptionCode.InvalidParameterValue:
                    case OwsExceptionCode.InvalidUpdateSequence:
                    case OwsExceptionCode.MissingParameterValue:
                        status = HttpStatusCode.BadRequest;
                        break;

                    case OwsExceptionCode.OperationNotSupported:
                    case OwsExceptionCode.OptionNotSupported:
                        status = HttpStatusCode.NotImplemented;
                        break;
                    }
                    fex = new WebFaultException <Ows100.ExceptionReport>((Ows100.ExceptionReport)oex, status);
                }
                else
                {
                    FaultCode fc = FaultCode.CreateReceiverFaultCode("InternalServerError", "http://schemas.microsoft.com/2009/WebFault");
                    fex = new FaultException(_Reason, fc);
                }
            }

            fault = CreateMessage(fex, version);
        }
Beispiel #19
0
 internal static FaultCode GetFaultCode(HttpStatusCode statusCode)
 {
     if ((int)statusCode >= (int)HttpStatusCode.InternalServerError)
     {
         return(FaultCode.CreateReceiverFaultCode(statusCode.ToString(), WebFaultCodeNamespace));
     }
     else
     {
         return(FaultCode.CreateSenderFaultCode(statusCode.ToString(), WebFaultCodeNamespace));
     }
 }
        /// <summary>
        /// Build the shielded MessageFault.
        /// </summary>
        /// <param name="serverException"></param>
        /// <param name="handlingInstanceId"></param>
        /// <returns></returns>
        private MessageFault BuildMessageFault(Exception serverException, Guid handlingInstanceId)
        {
            string exceptionMessage = ExceptionUtility.FormatExceptionMessage(
                Properties.Resources.ClientUnhandledExceptionMessage,
                ExceptionUtility.GetHandlingInstanceId(serverException, handlingInstanceId));

            FaultException faultException = new FaultException(
                new FaultReason(new FaultReasonText(exceptionMessage, CultureInfo.CurrentCulture)),
                FaultCode.CreateReceiverFaultCode(SoapException.ServerFaultCode.Name, SoapException.ServerFaultCode.Namespace));

            return(faultException.CreateMessageFault());
        }
Beispiel #21
0
        /// <summary>
        /// Generate fault message for a request message.
        /// </summary>
        /// <param name="requestMsg">request message</param>
        /// <returns>generated fault message</returns>
        private static Message GenerateFaultMessage(Message requestMsg)
        {
            MessageVersion version        = requestMsg.Headers.MessageVersion;
            SessionFault   sessionFault   = new SessionFault(SOAFaultCode.Service_InitializeFailed, StringTable.FailedToInitializeServiceHost);
            FaultReason    faultReason    = new FaultReason(StringTable.FailedToInitializeServiceHost);
            FaultCode      faultCode      = FaultCode.CreateReceiverFaultCode("ServiceHostInitializationFailed", Constant.HpcHeaderNS);
            FaultException faultException = new FaultException <SessionFault>(sessionFault, faultReason, faultCode, SessionFault.Action);
            MessageFault   fault          = faultException.CreateMessageFault();
            Message        faultMessage   = Message.CreateMessage(version, fault, faultException.Action);

            faultMessage.Headers.RelatesTo = requestMsg.Headers.MessageId;
            return(faultMessage);
        }
                public new void TryComplete(bool completedSynchronously, Exception exception)
                {
                    bool flag;
                    bool flag1 = false;

                    lock (base.ThisLock)
                    {
                        if (Interlocked.Exchange(ref this.completed, 1) == 0)
                        {
                            if (this.timer != null)
                            {
                                this.timer.Cancel();
                                this.timer = null;
                            }
                            flag1 = true;
                        }
                    }
                    if (flag1)
                    {
                        if (exception != null)
                        {
                            if (string.IsNullOrWhiteSpace(this.requestAction))
                            {
                                flag = false;
                            }
                            else
                            {
                                flag = (this.requestAction.Equals("http://schemas.microsoft.com/netservices/2011/06/servicebus/SbmpMessageSender/Send", StringComparison.OrdinalIgnoreCase) ? true : this.requestAction.Equals("http://schemas.microsoft.com/netservices/2011/06/servicebus/SbmpMessageReceiver/SetSessionState", StringComparison.OrdinalIgnoreCase));
                            }
                            if (flag && this.parent.IsMaxMessageSizeExceededFault)
                            {
                                string          str             = SRClient.TrackableExceptionMessageFormat(SRClient.MessageSizeExceeded, this.CreateClientTrackingExceptionInfo());
                                ExceptionDetail exceptionDetail = new ExceptionDetail(new MessageSizeExceededException(str));
                                FaultCode       faultCode       = FaultCode.CreateReceiverFaultCode("InternalServiceFault", "http://schemas.microsoft.com/netservices/2011/06/servicebus");
                                FaultReason     faultReason     = new FaultReason(new FaultReasonText(str, CultureInfo.CurrentCulture));
                                if (!this.parent.includeExceptionDetails)
                                {
                                    exception = new FaultException <ExceptionDetailNoStackTrace>(new ExceptionDetailNoStackTrace(exceptionDetail, true), faultReason, faultCode);
                                }
                                else
                                {
                                    exception = new FaultException <ExceptionDetail>(exceptionDetail, faultReason, faultCode);
                                }
                            }
                        }
                        this.parent.OnEndRequest();
                        base.Complete(completedSynchronously, exception);
                    }
                }
        public void TestReceiverFaultCode()
        {
            code = FaultCode.CreateReceiverFaultCode("foo", "bar");
            Assert.IsTrue(code.IsReceiverFault);
            Assert.AreEqual("Receiver", code.Name);
            Assert.AreEqual(String.Empty, code.Namespace);
            Assert.AreEqual("foo", code.SubCode.Name);
            Assert.AreEqual("bar", code.SubCode.Namespace);

            code = new FaultCode("Receiver");
            Assert.IsTrue(code.IsReceiverFault);

            code = new FaultCode("something else");
            Assert.IsFalse(code.IsReceiverFault);
        }
Beispiel #24
0
        /// <summary>
        /// Put the request item into the storage. and the storage will cache the requests in the memory
        /// until the front end call the flush method. the async result will return the BrokerQueueItem.
        /// </summary>
        /// <param name="context">the request context relate to the message</param>
        /// <param name="msg">the request message</param>
        /// <param name="asyncState">the asyncState relate to the message</param>
        public override async Task PutRequestAsync(Telepathy.ServiceBroker.FrontEnd.RequestContextBase context, Message msg, object asyncState)
        {
            this.queue.Enqueue(new BrokerQueueItem(context, msg, asyncState));
            if (this.directReply)
            {
                MessageFault fault = MessageFault.CreateFault(FaultCode.CreateReceiverFaultCode("DummyReply", "http://hpc.microsoft.com"), "DummyReply");
                Message      reply = Message.CreateMessage(context.MessageVersion, fault, msg.Headers.Action + "Response");
                if (context.MessageVersion == MessageVersion.Default)
                {
                    reply.Headers.RelatesTo = msg.Headers.MessageId;
                }

                context.Reply(reply, TimeSpan.MaxValue);
            }
        }
Beispiel #25
0
        private FaultCode CreateFaultCode(OiosiFaultCode faultCode, OiosiInnerFaultCode innerFaultCode)
        {
            switch (faultCode)
            {
            case OiosiFaultCode.Sender:
                FaultCode senderInnerFaultCode = CreateSenderFaultCode(innerFaultCode);
                return(FaultCode.CreateSenderFaultCode(senderInnerFaultCode));

            case OiosiFaultCode.Receiver:
                FaultCode recieverInnerFaultCode = CreateRecieverFaultCode(innerFaultCode);
                return(FaultCode.CreateReceiverFaultCode(recieverInnerFaultCode));

            default:
                throw new OiosiMessageFaultUnexpectedFaultCode(faultCode);
            }
        }
Beispiel #26
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="error"></param>
        /// <param name="version"></param>
        /// <param name="fault"></param>
        public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
        {
            if (error is FaultException)
            {
                return;
            }

            var faultDetail = new ErrorHelper().ConstruirError(error);

            var          faultType      = typeof(FaultException <>).MakeGenericType(faultDetail.GetType());
            var          faultReason    = new FaultReason(faultDetail.Description);
            var          faultCode      = FaultCode.CreateReceiverFaultCode(new FaultCode(faultDetail.SubCode));
            var          faultException = (FaultException)Activator.CreateInstance(faultType, faultDetail, faultReason, faultCode);
            MessageFault faultMessage   = faultException.CreateMessageFault();

            fault = Message.CreateMessage(version, faultMessage, faultException.Action);
        }
        public void TestIsPredefinedCode()
        {
            code = new FaultCode("foo");
            Assert.IsTrue(code.IsPredefinedFault);

            code = new FaultCode("foo", String.Empty);
            Assert.IsTrue(code.IsPredefinedFault);

            code = new FaultCode("foo", "bar");
            Assert.IsFalse(code.IsPredefinedFault);

            code = FaultCode.CreateReceiverFaultCode(new FaultCode("foo", "bar"));
            Assert.IsTrue(code.IsPredefinedFault);
            Assert.IsFalse(code.SubCode.IsPredefinedFault);

            code = FaultCode.CreateReceiverFaultCode(new FaultCode("foo"));
            Assert.IsTrue(code.IsPredefinedFault);
            Assert.IsTrue(code.SubCode.IsPredefinedFault);
        }
Beispiel #28
0
            public override void AfterReceiveReply(ref Message reply, object correlationState)
            {
                bool callBase = true;

                if (reply != null)
                {
                    object responseProperty = reply.Properties[HttpResponseMessageProperty.Name];
                    if (responseProperty != null)
                    {
                        if (((HttpResponseMessageProperty)responseProperty).Headers[JsonGlobals.jsonerrorString] == JsonGlobals.trueString)
                        {
                            callBase = false;
                            XmlDictionaryReader reader      = reply.GetReaderAtBodyContents();
                            JsonFaultDetail     faultDetail = jsonFaultSerializer.ReadObject(reader) as JsonFaultDetail;
                            FaultCode           faultCode   = new FaultCode(FaultCodeConstants.Codes.InternalServiceFault, FaultCodeConstants.Namespaces.NetDispatch);
                            faultCode = FaultCode.CreateReceiverFaultCode(faultCode);
                            if (faultDetail != null)
                            {
                                if (faultDetail.ExceptionDetail != null)
                                {
                                    throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                                              new FaultException <ExceptionDetail>(faultDetail.ExceptionDetail, faultDetail.Message, faultCode));
                                }
                                else
                                {
                                    throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                                              new FaultException(MessageFault.CreateFault(faultCode, faultDetail.Message)));
                                }
                            }
                            else
                            {
                                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                                          new FaultException(MessageFault.CreateFault(faultCode,
                                                                                      System.ServiceModel.SR.GetString(System.ServiceModel.SR.SFxInternalServerError))));
                            }
                        }
                    }
                }
                if (callBase)
                {
                    base.AfterReceiveReply(ref reply, correlationState);
                }
            }
Beispiel #29
0
        Message CreateFault(Message request, Exception e)
        {
            MessageVersion version = request.Version;
            FaultCode      subCode;
            FaultReason    reason;
            bool           isSenderFault;

            if (e is SecurityTokenValidationException || e is System.ComponentModel.Win32Exception)
            {
                subCode       = new FaultCode(TrustApr2004Strings.FailedAuthenticationFaultCode, TrustFeb2005Strings.Namespace);
                reason        = new FaultReason(SR.GetString(SR.FailedAuthenticationTrustFaultCode), CultureInfo.CurrentCulture);
                isSenderFault = true;
            }
            else if (e is QuotaExceededException)
            {
                // send a receiver fault so that the sender can retry
                subCode       = new FaultCode(DotNetSecurityStrings.SecurityServerTooBusyFault, DotNetSecurityStrings.Namespace);
                reason        = new FaultReason(SR.GetString(SR.NegotiationQuotasExceededFaultReason), CultureInfo.CurrentCulture);
                isSenderFault = false;
            }
            else
            {
                subCode       = new FaultCode(TrustApr2004Strings.InvalidRequestFaultCode, TrustFeb2005Strings.Namespace);
                reason        = new FaultReason(SR.GetString(SR.InvalidRequestTrustFaultCode), CultureInfo.CurrentCulture);
                isSenderFault = true;
            }
            FaultCode faultCode;

            if (isSenderFault)
            {
                faultCode = FaultCode.CreateSenderFaultCode(subCode);
            }
            else
            {
                faultCode = FaultCode.CreateReceiverFaultCode(subCode);
            }
            MessageFault fault      = MessageFault.CreateFault(faultCode, reason);
            Message      faultReply = Message.CreateMessage(version, fault, version.Addressing.DefaultFaultAction);

            faultReply.Headers.RelatesTo = request.Headers.MessageId;

            return(faultReply);
        }
Beispiel #30
0
        public void ProvideFault(Exception error,
                                 System.ServiceModel.Channels.MessageVersion version,
                                 ref System.ServiceModel.Channels.Message fault)
        {
            if (m_ReentrancyCheck)
            {
                return;
            }

            m_ReentrancyCheck = true;

            try
            {
                if ((fault == null) && (error != null))
                {
                    ReceiverFaultDetail receiverFaultDetail = new ReceiverFaultDetail(
                        error.Message, getDescription(error), StackHashException.GetServiceErrorCode(error));

                    FaultException <ReceiverFaultDetail> fe = new FaultException <ReceiverFaultDetail>(
                        receiverFaultDetail, error.Message, FaultCode.CreateReceiverFaultCode(new FaultCode("ReceiverFault")));

                    MessageFault mf = fe.CreateMessageFault();

                    fault = Message.CreateMessage(version, mf, fe.Action);


                    try
                    {
                        DiagnosticsHelper.LogException(DiagSeverity.Warning, "Service exception occurred", error);
                    }
                    catch (System.Exception)
                    {
                        // Ignore the error.
                    }
                }
            }
            finally
            {
                m_ReentrancyCheck = false;
            }
        }