Ejemplo n.º 1
0
        Task ReplyAddressFilterDidNotMatchAsync(RequestContext request, RequestInfo requestInfo)
        {
            FaultCode code = FaultCode.CreateSenderFaultCode(AddressingStrings.DestinationUnreachable,
                                                             _messageVersion.Addressing.Namespace);
            string reason = SR.Format(SR.SFxNoEndpointMatchingAddress, request.RequestMessage.Headers.To);

            return(ReplyFailureAsync(request, requestInfo, code, reason));
        }
Ejemplo n.º 2
0
        private void ReplyAddressFilterDidNotMatch(RequestContext request)
        {
            FaultCode code = FaultCode.CreateSenderFaultCode(AddressingStrings.DestinationUnreachable,
                                                             _messageVersion.Addressing.Namespace);
            string reason = SR.Format(SR.SFxNoEndpointMatchingAddress, request.RequestMessage.Headers.To);

            ReplyFailure(request, code, reason);
        }
        internal static FaultException CreateAccessDeniedFaultException()
        {
            SecurityVersion wss         = SecurityVersion.WSSecurity11;
            FaultCode       faultCode   = FaultCode.CreateSenderFaultCode("FailedAuthentication", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
            FaultReason     faultReason = new FaultReason(new FaultReasonText("Access is denied", CultureInfo.CurrentCulture));

            return(new FaultException(faultReason, faultCode));
        }
Ejemplo n.º 4
0
        internal static Exception CreateAccessDeniedFaultException()
        {
            SecurityVersion wss         = SecurityVersion.Default;
            FaultCode       faultCode   = FaultCode.CreateSenderFaultCode(wss.FailedAuthenticationFaultCode.Value, wss.HeaderNamespace.Value);
            FaultReason     faultReason = new FaultReason(SR.AccessDenied, CultureInfo.CurrentCulture);

            return(new FaultException(faultReason, faultCode));
        }
Ejemplo n.º 5
0
        internal static Exception CreateFailedAuthenticationFaultException()
        {
            SecurityVersion wss         = SecurityVersion.Default;
            FaultCode       faultCode   = FaultCode.CreateSenderFaultCode(wss.InvalidSecurityFaultCode.Value, wss.HeaderNamespace.Value);
            FaultReason     faultReason = new FaultReason(SR.AuthenticationOfClientFailed);

            return(new FaultException(faultReason, faultCode));
        }
Ejemplo n.º 6
0
        internal static NetDispatcherFaultException CreateDeserializationFailedFault(string reason, Exception innerException)
        {
            reason = SR.Format(SR.SFxDeserializationFailed1, reason);
            FaultCode code = new FaultCode(FaultCodeConstants.Codes.DeserializationFailed, FaultCodeConstants.Namespaces.NetDispatch);

            code = FaultCode.CreateSenderFaultCode(code);
            return(new NetDispatcherFaultException(reason, code, innerException));
        }
Ejemplo n.º 7
0
 public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
 {
     fault = Message.CreateMessage(version,
                                   FaultCode.CreateSenderFaultCode("BadEvalSubmission", "http://learningwcf.com/evals"),
                                   "Bad Eval Submitted (IErrorHandler)",
                                   new BadEvalSubmission(),
                                   "http://learningwcf.com/IEvalService/SubmitEvalBadEvalSubmissionFault");
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Builds a fault message for to return to the caller
        /// </summary>
        /// <remarks>
        /// Builds an undeclared SOAP fault (using FaultException, rather than generic FaultException),
        /// for interop with non-WCF clients which won't recognise declared SOAP faults
        /// </remarks>
        /// <param name="error">Unhandled exception</param>
        /// <param name="version">Message version</param>
        /// <param name="fault">Fault message</param>
        public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
        {
            //build undeclared SOAP fault:
            FaultException ex           = new FaultException(error.Message, FaultCode.CreateSenderFaultCode(SoapException.ServerFaultCode.Name, SoapException.ServerFaultCode.Namespace));
            MessageFault   messageFault = ex.CreateMessageFault();

            fault = Message.CreateMessage(version, messageFault, this.ServiceName);
        }
Ejemplo n.º 9
0
        public void ProvideFault(Exception error, MessageVersion version,
                                 ref Message fault)
        {
            FaultCode faultCode =
                FaultCode.CreateSenderFaultCode(error.GetType().Name,
                                                ServiceConstants.Error);

            fault = Message.CreateMessage(version, faultCode, error.Message, null);
        }
Ejemplo n.º 10
0
        internal static Exception CreateFailedAuthenticationFaultException()
        {
            // always use default version?
            SecurityVersion wss         = SecurityVersion.Default;
            FaultCode       faultCode   = FaultCode.CreateSenderFaultCode(wss.InvalidSecurityFaultCode.Value, wss.HeaderNamespace.Value);
            FaultReason     faultReason = new FaultReason(SR.GetString(SR.AuthenticationOfClientFailed), CultureInfo.CurrentCulture);

            return(new FaultException(faultReason, faultCode));
        }
Ejemplo n.º 11
0
            public Task <object> InvokeAsync(object instance, object[] inputs, out object[] outputs)
            {
                outputs = EmptyArray <object> .Allocate(0);

                Message message = inputs[0] as Message;

                if (message == null)
                {
                    return(null);
                }

                string action = message.Headers.Action;

                FaultCode code = FaultCode.CreateSenderFaultCode(AddressingStrings.ActionNotSupported,
                                                                 message.Version.Addressing.Namespace);
                string      reasonText = SR.Format(SR.SFxNoEndpointMatchingContract, action);
                FaultReason reason     = new FaultReason(reasonText);

                FaultException exception = new FaultException(reason, code);

                ErrorBehavior.ThrowAndCatch(exception);

                ServiceChannel serviceChannel = OperationContext.Current.InternalServiceChannel;

                OperationContext.Current.OperationCompleted +=
                    delegate(object sender, EventArgs e)
                {
                    ChannelDispatcher channelDispatcher = _dispatchRuntime.ChannelDispatcher;
                    if (!channelDispatcher.HandleError(exception) && serviceChannel.HasSession)
                    {
                        try
                        {
                            serviceChannel.Close(ChannelHandler.CloseAfterFaultTimeout);
                        }
                        catch (Exception ex)
                        {
                            if (Fx.IsFatal(ex))
                            {
                                throw;
                            }
                            channelDispatcher.HandleError(ex);
                        }
                    }
                };

                if (_dispatchRuntime._shared.EnableFaults)
                {
                    MessageFault fault = MessageFault.CreateFault(code, reason, action);
                    return(Task.FromResult((object)Message.CreateMessage(message.Version, fault, message.Version.Addressing.DefaultFaultAction)));
                }
                else
                {
                    OperationContext.Current.RequestContext.Close();
                    OperationContext.Current.RequestContext = null;
                    return(Task.FromResult((object)null));
                }
            }
Ejemplo n.º 12
0
 private static MessageFault GetSecureConversationCloseNotSupportedFault()
 {
     if (s_secureConversationCloseNotSupportedFault == null)
     {
         FaultCode   faultCode   = FaultCode.CreateSenderFaultCode(DotNetSecurityStrings.SecureConversationCancelNotAllowedFault, DotNetSecurityStrings.Namespace);
         FaultReason faultReason = new FaultReason(SR.Format(SR.SecureConversationCancelNotAllowedFaultReason), System.Globalization.CultureInfo.InvariantCulture);
         s_secureConversationCloseNotSupportedFault = MessageFault.CreateFault(faultCode, faultReason);
     }
     return(s_secureConversationCloseNotSupportedFault);
 }
Ejemplo n.º 13
0
        private Task ReplyChannelTerminatedAsync(RequestContext request, RequestInfo requestInfo)
        {
            FaultCode code = FaultCode.CreateSenderFaultCode(FaultCodeConstants.Codes.SessionTerminated,
                                                             FaultCodeConstants.Namespaces.NetDispatch);
            string  reason = SR.SFxChannelTerminated0;
            string  action = FaultCodeConstants.Actions.NetDispatcher;
            Message fault  = Message.CreateMessage(_messageVersion, code, reason, action);

            return(ReplyFailureAsync(request, requestInfo, fault, action, reason, code));
        }
Ejemplo n.º 14
0
        private void ReplyChannelTerminated(RequestContext request)
        {
            FaultCode code = FaultCode.CreateSenderFaultCode(FaultCodeConstants.Codes.SessionTerminated,
                                                             FaultCodeConstants.Namespaces.NetDispatch);
            string  reason = SR.Format(SR.SFxChannelTerminated0);
            string  action = FaultCodeConstants.Actions.NetDispatcher;
            Message fault  = Message.CreateMessage(_messageVersion, code, reason, action);

            ReplyFailure(request, fault, action, reason, code);
        }
Ejemplo n.º 15
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));
     }
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Called when request executed.
 /// </summary>
 /// <param name="onAction">The on request action.</param>
 /// <exception cref="FaultException"></exception>
 /// <exception cref="FaultReason"></exception>
 private void OnAction(Action onAction)
 {
     try
     {
         onAction();
     }
     catch (Exception e)
     {
         throw new FaultException(new FaultReason(e.Message), FaultCode.CreateSenderFaultCode("err", "test"));
     }
 }
Ejemplo n.º 17
0
        public static Message CreateFaultMessage(UniqueId messageID, MessageVersion messageVersion, Fault fault)
        {
            MessageFault fault2  = MessageFault.CreateFault(FaultCode.CreateSenderFaultCode(fault.Code), fault.Reason);
            Message      message = Message.CreateMessage(messageVersion, fault2, messageVersion.Addressing.FaultAction);

            message.Headers.Action = fault.Action;
            if (messageID != null)
            {
                message.Headers.RelatesTo = messageID;
            }
            return(message);
        }
Ejemplo n.º 18
0
 public WorkflowOperationFault(MessageQueueErrorCode errorCode)
 {
     if (errorCode == MessageQueueErrorCode.QueueNotAvailable)
     {
         faultCode   = FaultCode.CreateSenderFaultCode(operationNotAvailable, ContextMessageHeader.ContextHeaderNamespace);
         faultReason = new FaultReason(new FaultReasonText(SR2.GetString(SR2.OperationNotAvailable), CultureInfo.CurrentCulture));
     }
     else
     {
         faultCode   = FaultCode.CreateSenderFaultCode(operationNotImplemented, ContextMessageHeader.ContextHeaderNamespace);
         faultReason = new FaultReason(new FaultReasonText(SR2.GetString(SR2.OperationNotImplemented), CultureInfo.CurrentCulture));
     }
 }
Ejemplo n.º 19
0
        static void Main(string[] args)
        {
            FaultCode       code        = FaultCode.CreateSenderFaultCode("calcuError", "http://www.artech.com");
            FaultReasonText reasonText1 = new FaultReasonText("Divided by zero!", "en-US");
            FaultReasonText reasonText2 = new FaultReasonText("试图除以零!", "zh-CN");
            FaultReason     reason      = new FaultReason(new FaultReasonText[] { reasonText1, reasonText2 });
            MessageFault    fault       = MessageFault.CreateFault(code, reason);
            string          action      = "http://www.artech.com/divideFault";

            using (Message message = Message.CreateMessage(MessageVersion.Default, fault, action))
            {
                WriteMessage(message, "message.xml");
            }
        }
Ejemplo n.º 20
0
        public virtual IEnumerable <string> Find(string costCenterCriteria)
        {
            if (costCenterCriteria == "WebFaultException")
            {
                throw new WebFaultException <string>("Custom exception", HttpStatusCode.GatewayTimeout);
            }

            if (costCenterCriteria == "FaultException")
            {
                throw new FaultException("Default exception", FaultCode.CreateSenderFaultCode("hej", "hej"));
            }

            return(this._test.GetList(costCenterCriteria));
        }
Ejemplo n.º 21
0
            public object Invoke(object instance, object[] inputs, out object[] outputs)
            {
                FaultException exception;
                ServiceChannel serviceChannel;

                outputs = EmptyArray <object> .Allocate(0);

                Message message = inputs[0] as Message;

                if (message != null)
                {
                    string action = message.Headers.Action;
                    if (DiagnosticUtility.ShouldTraceInformation)
                    {
                        TraceUtility.TraceEvent(TraceEventType.Information, 0x80037, System.ServiceModel.SR.GetString("TraceCodeUnhandledAction"), new StringTraceRecord("Action", action), this, null, message);
                    }
                    FaultCode   code   = FaultCode.CreateSenderFaultCode("ActionNotSupported", message.Version.Addressing.Namespace);
                    FaultReason reason = new FaultReason(System.ServiceModel.SR.GetString("SFxNoEndpointMatchingContract", new object[] { action }));
                    exception = new FaultException(reason, code);
                    System.ServiceModel.Dispatcher.ErrorBehavior.ThrowAndCatch(exception);
                    serviceChannel = OperationContext.Current.InternalServiceChannel;
                    OperationContext.Current.OperationCompleted += delegate(object sender, EventArgs e) {
                        ChannelDispatcher channelDispatcher = this.dispatchRuntime.ChannelDispatcher;
                        if (!channelDispatcher.HandleError(exception) && serviceChannel.HasSession)
                        {
                            try
                            {
                                serviceChannel.Close(ChannelHandler.CloseAfterFaultTimeout);
                            }
                            catch (Exception exception1)
                            {
                                if (Fx.IsFatal(exception1))
                                {
                                    throw;
                                }
                                channelDispatcher.HandleError(exception1);
                            }
                        }
                    };
                    if (this.dispatchRuntime.shared.EnableFaults)
                    {
                        MessageFault fault = MessageFault.CreateFault(code, reason, action);
                        return(Message.CreateMessage(message.Version, fault, message.Version.Addressing.DefaultFaultAction));
                    }
                    OperationContext.Current.RequestContext.Close();
                    OperationContext.Current.RequestContext = null;
                }
                return(null);
            }
        /// <summary>
        /// Build the unshielded MessageFault.
        /// </summary>
        /// <param name="faultContractWrapper"></param>
        /// <returns></returns>
        private MessageFault BuildMessageFault(FaultContractWrapperException faultContractWrapper)
        {
            Type faultExceptionType            = typeof(FaultException <>);
            Type constructedFaultExceptionType = faultExceptionType.MakeGenericType(faultContractWrapper.FaultContract.GetType());

            //Encapsulate the FaultContract in the FaultException
            FaultException faultException =
                (FaultException)Activator.CreateInstance(
                    constructedFaultExceptionType,
                    faultContractWrapper.FaultContract,
                    new FaultReason(new FaultReasonText(faultContractWrapper.Message, CultureInfo.CurrentCulture)),
                    FaultCode.CreateSenderFaultCode(SoapException.ClientFaultCode.Name, SoapException.ClientFaultCode.Namespace));

            return(faultException.CreateMessageFault());
        }
        public void TestSenderFaultCode()
        {
            code = FaultCode.CreateSenderFaultCode("foo", "bar");
            Assert.IsTrue(code.IsSenderFault);
            Assert.AreEqual("Sender", code.Name);
            Assert.AreEqual(String.Empty, code.Namespace);
            Assert.AreEqual("foo", code.SubCode.Name);
            Assert.AreEqual("bar", code.SubCode.Namespace);

            code = new FaultCode("Sender");
            Assert.IsTrue(code.IsSenderFault);

            code = new FaultCode("something else");
            Assert.IsFalse(code.IsReceiverFault);
        }
Ejemplo n.º 24
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);
            }
        }
 public void BeforeSendReply(ref Message reply, object correlationState)
 {
     try
     {
         reply.ToString();
     }
     catch (Exception e)
     {
         var faultCode   = FaultCode.CreateSenderFaultCode(null);
         var faultReason = new FaultReason(e.GetBaseException().Message);
         reply = Message.CreateMessage(
             reply.Version,
             MessageFault.CreateFault(faultCode, faultReason),
             null);
     }
 }
Ejemplo n.º 26
0
 public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
 {
     try
     {
         FaultReason     faultReason     = new FaultReason(error.Message);
         ExceptionDetail exceptionDetail = new ExceptionDetail(error);
         FaultCode       faultCode       = FaultCode.CreateSenderFaultCode(new FaultCode("0"));
         FaultException <ExceptionDetail> faultException = new FaultException <ExceptionDetail>(exceptionDetail, faultReason, faultCode);
         MessageFault messageFault = faultException.CreateMessageFault();
         fault = Message.CreateMessage(version, messageFault, faultException.Action);
     }
     catch
     {
         // Todo log error
     }
 }
Ejemplo n.º 27
0
        private FaultException ConstructSoapFaultException(Exception e)
        {
            var moviesException = e as MoviesBaseException;

            string faultReason;

            if (moviesException != null)
            {
                faultReason = moviesException.Reason + "\r\n" + e.Message;
            }
            else
            {
                faultReason = e.Message;
            }

            return(new FaultException(faultReason, FaultCode.CreateSenderFaultCode(e.GetType().Name, "http://www.matlus.com/gateway/Movies")));
        }
 public void AttemptSimplePasswordReset(object sender, XmlDocumentValidationEventArgs e)
 {
     if (e.XmlDocument is SimplePWResetDocument)
     {
         this.xmlInteractiveActivity1.ReferenceProperties = new ReferencePropertiesType(new Microsoft.ResourceManagement.WebServices.UniqueIdentifier("SimplePWResetDocument"));
         this.xmlInteractiveActivity1.ResourceAddress     = new Uri("http://NotUsableAddress/");
     }
     else
     {
         this.xmlInteractiveActivity1.CreateFaultMessage = new FaultException(
             MessageFault.CreateFault(
                 FaultCode.CreateSenderFaultCode("DataRequiredFault", "http://schemas.xmlsoap.org/ws/2004/09/transfer/fault"),
                 new FaultReason(new FaultReasonText("DataRequiredFaultReason")),
                 new DataRequiredFault(SimplePasswordReset.ObjectTypeRequested, "Your password was not long enough"),
                 new ClientSerializer(typeof(DataRequiredFault))));
     }
 }
Ejemplo n.º 29
0
 public void SubmitEvals(Eval eval)
 {
     if (eval.Submitter.Equals("throw1"))
     {
         throw new Exception("Something Bad Happened");
     }
     else if (eval.Submitter.Equals("throw2"))
     {
         throw new FaultException("Something Bad Happened",
                                  FaultCode.CreateSenderFaultCode("Bad Submitter Name", "http://learningwcf.com/faultexception"));
     }
     else if (eval.Submitter.Equals("throw3"))
     {
         throw new FaultException <BadEvalSubmission>(new BadEvalSubmission());
     }
     evalList.Add(eval);
     Console.WriteLine($" Service received from : {eval.Submitter} at {eval.Timespent}");
 }
Ejemplo n.º 30
0
        internal static Exception CreateFault(string reasonText, string codeString, bool isNetDispatcherFault)
        {
            string str;
            string str2;

            if (isNetDispatcherFault)
            {
                str  = "http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher";
                str2 = "http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher/fault";
            }
            else
            {
                str  = "http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/transactions";
                str2 = "http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/transactions/fault";
            }
            FaultReason reason = new FaultReason(reasonText, CultureInfo.CurrentCulture);

            return(new FaultException(reason, FaultCode.CreateSenderFaultCode(codeString, str), str2));
        }