public void TryCreateExceptionDefault() { var msg = Message.CreateMessage(XmlReader.Create(new StringReader(xml1)), 0x1000, MessageVersion.Soap11WSAddressing10); var mf = MessageFault.CreateFault(msg, 1000); msg = Message.CreateMessage(XmlReader.Create(new StringReader(xml1)), 0x1000, MessageVersion.Soap11WSAddressing10); Exception ex; Assert.IsTrue(s11.TryCreateException(msg, mf, out ex), "#1"); // foobar -> false Assert.IsFalse(s11.TryCreateException(msg, MessageFault.CreateFault(new FaultCode("foobar"), new FaultReason("foobar reason")), out ex), "#2"); // SOAP 1.1 ActionNotSupported -> true Assert.IsTrue(s11.TryCreateException(msg, MessageFault.CreateFault(new FaultCode("ActionNotSupported", Constants.WsaNamespace), new FaultReason("foobar reason")), out ex), "#3"); Assert.IsTrue(ex is ActionNotSupportedException, "#3-2"); Assert.IsTrue(ex.Message.IndexOf("foobar") >= 0, "#3-3"); // SOAP 1.1 Sender/ActionNotSupported -> false mf = MessageFault.CreateFault(new FaultCode("Sender", new FaultCode("ActionNotSupported", Constants.WsaNamespace)), new FaultReason("foobar reason")); Assert.IsFalse(s11.TryCreateException(msg, mf, out ex), "#4"); // SOAP 1.2 ActionNotSupported -> false mf = MessageFault.CreateFault(new FaultCode("ActionNotSupported", Constants.WsaNamespace), new FaultReason("foobar reason")); Assert.IsFalse(s12.TryCreateException(msg, mf, out ex), "#5"); // SOAP 1.2 Sender/ActionNotSupported -> true mf = MessageFault.CreateFault(new FaultCode("Sender", new FaultCode("ActionNotSupported", Constants.WsaNamespace)), new FaultReason("foobar reason")); Assert.IsTrue(s12.TryCreateException(msg, mf, out ex), "#6"); Assert.IsTrue(ex is ActionNotSupportedException, "#6-2"); Assert.IsTrue(ex.Message.IndexOf("foobar") >= 0, "#6-3"); }
private void ThrowIfFaultMessage(Message wcfMessage) { Exception exception; if (wcfMessage.IsFault) { MessagingClientEtwProvider.TraceClient(() => { }); string action = wcfMessage.Headers.Action; MessageFault messageFault = MessageFault.CreateFault(wcfMessage, 65536); FaultConverter property = this.innerChannel.GetProperty <FaultConverter>(); if (property == null || !property.TryCreateException(wcfMessage, messageFault, out exception)) { if (!messageFault.HasDetail) { throw Microsoft.ServiceBus.Messaging.FxTrace.Exception.AsWarning(new FaultException(messageFault, action), null); } ExceptionDetail detail = messageFault.GetDetail <ExceptionDetail>(); if (!this.clientMode && string.Equals(detail.Type, typeof(CommunicationException).FullName, StringComparison.Ordinal)) { MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.EventWriteRuntimeChannelFaulting(this.innerChannel.GetType().Name, this.innerChannel.LocalAddress.Uri.AbsoluteUri, this.innerChannel.RemoteAddress.Uri.AbsoluteUri, this.innerChannel.Via.AbsoluteUri, this.innerChannel.Session.Id, string.Concat("ThrowIfFaultMessage: Received CommunicationException as fault message. ", detail.ToString()))); base.Fault(); } if (!this.includeExceptionDetails) { throw Microsoft.ServiceBus.Messaging.FxTrace.Exception.AsInformation(new FaultException <ExceptionDetailNoStackTrace>(new ExceptionDetailNoStackTrace(detail, true), messageFault.Reason, messageFault.Code, action), null); } throw Microsoft.ServiceBus.Messaging.FxTrace.Exception.AsInformation(new FaultException <ExceptionDetail>(detail, messageFault.Reason, messageFault.Code, action), null); } throw Fx.Exception.AsWarning(exception, null); } }
private Exception DeserializeFault(System.ServiceModel.Channels.Message inMessage, FaultConverter faultConverter) { MessageFault fault = MessageFault.CreateFault(inMessage, 0x10000); string action = inMessage.Headers.Action; if (action == inMessage.Version.Addressing.DefaultFaultAction) { action = null; } Exception exception = null; if (faultConverter != null) { faultConverter.TryCreateException(inMessage, fault, out exception); } if (exception == null) { exception = this.FaultFormatter.Deserialize(fault, action); } if (inMessage.State != MessageState.Created) { inMessage.Close(); } return(exception); }
Exception DeserializeFault(Message inMessage, FaultConverter faultConverter) { // Reproduce logic in ClientOperationFormatterHelper MessageFault messageFault = MessageFault.CreateFault(inMessage, TransportDefaults.MaxFaultSize); string action = inMessage.Headers.Action; if (action == inMessage.Version.Addressing.DefaultFaultAction) { action = null; } Exception exception = null; if (faultConverter != null) { faultConverter.TryCreateException(inMessage, messageFault, out exception); } if (exception == null) { exception = this.FaultFormatter.Deserialize(messageFault, action); } if (inMessage.State != MessageState.Created) { inMessage.Close(); } return(exception); }
public void TryCreateExceptionMessageNullDefault() { var msg = Message.CreateMessage(XmlReader.Create(new StringReader(xml1)), 0x1000, MessageVersion.Soap11WSAddressing10); var mf = MessageFault.CreateFault(msg, 1000); Exception ex; s11.TryCreateException(null, mf, out ex); }
protected override bool OnTryCreateException(Message message, MessageFault fault, out Exception exception) { if (_innerChannel == null) { exception = null; return(false); } FaultConverter inner = _innerChannel.GetProperty <FaultConverter>(); if (inner != null) { return(inner.TryCreateException(message, fault, out exception)); } else { exception = null; return(false); } }
/// <summary> /// Converts fault to exception and throws it /// </summary> /// <param name="response">Response message</param> /// <param name="fault">Fault message</param> /// <param name="action">SOAP Action</param> /// <param name="version">Message Version</param> private static void ThrowIfFaultUnderstood( Message response, MessageFault fault, string action, MessageVersion version) { Exception exception; bool isSenderFault; bool isReceiverFault; FaultCode subCode; FaultConverter faultConverter = FaultConverter.GetDefaultFaultConverter(version); if (faultConverter.TryCreateException(response, fault, out exception)) { throw exception; } if (version.Envelope == EnvelopeVersion.Soap11) { isSenderFault = true; isReceiverFault = true; subCode = fault.Code; } else { isSenderFault = fault.Code.IsSenderFault; isReceiverFault = fault.Code.IsReceiverFault; subCode = fault.Code.SubCode; } if ((subCode != null) && (subCode.Namespace != null)) { if (isSenderFault) { if (string.Compare(subCode.Namespace, "http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher", StringComparison.Ordinal) == 0) { if (string.Compare(subCode.Name, "SessionTerminated", StringComparison.Ordinal) == 0) { throw new ChannelTerminatedException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text); } if (string.Compare(subCode.Name, "TransactionAborted", StringComparison.Ordinal) == 0) { throw new ProtocolException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text); } } } if (isReceiverFault && (string.Compare(subCode.Namespace, "http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher", StringComparison.Ordinal) == 0)) { if (string.Compare(subCode.Name, "InternalServiceFault", StringComparison.Ordinal) == 0) { if (fault.HasDetail) { ExceptionDetail detail = fault.GetDetail <ExceptionDetail>(); throw new FaultException <ExceptionDetail>(detail, fault.Reason, fault.Code, action); } throw new FaultException(fault, action); } if (string.Compare(subCode.Name, "DeserializationFailed", StringComparison.Ordinal) == 0) { throw new ProtocolException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text); } } } throw new FaultException(fault); }