// 1) version, code, reason, action -> 3 // 2) version, code, reason, detail, action -> 3 // 3) version, fault, action -> SimpleMessage // 4) version, action, body -> 10 or 5 // 5) version, action, body, formatter -> 10 or 9 // 6) version, action, xmlReader -> 7 // 7) version, action, reader -> 9 // 8) xmlReader, maxSizeOfHeaders, version -> 11 // 9) version, action, body -> SimpleMessage // 10) version, action -> EmptyMessage // 11) reader, maxSizeOfHeaders, version -> XmlReaderMessage // 1) public static Message CreateMessage(MessageVersion version, FaultCode code, string reason, string action) { MessageFault fault = MessageFault.CreateFault(code, reason); return(CreateMessage(version, fault, 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)); }
private void ValidateResponse(Message response) { if (response != null) { if ((response.Version == MessageVersion.None) && (response is NullMessage)) { response.Close(); } else { Exception innerException = null; if (response.IsFault) { try { innerException = new FaultException(MessageFault.CreateFault(response, 0x10000)); } catch (Exception exception2) { if (Fx.IsFatal(exception2)) { throw; } if ((!(exception2 is CommunicationException) && !(exception2 is TimeoutException)) && (!(exception2 is XmlException) && !(exception2 is IOException))) { throw; } innerException = exception2; } } throw TraceUtility.ThrowHelperError(new ProtocolException(System.ServiceModel.SR.GetString("OneWayUnexpectedResponse"), innerException), response); } } }
// 2) public static Message CreateMessage(MessageVersion version, FaultCode code, string reason, object detail, string action) { MessageFault fault = MessageFault.CreateFault( code, new FaultReason(reason), detail); return(CreateMessage(version, fault, action)); }
public static Exception CreateCSFaultException(MessageVersion version, ReliableMessagingVersion reliableMessagingVersion, Message message, IChannel innerChannel) { FaultCode subCode; Exception exception; MessageFault messageFault = MessageFault.CreateFault(message, 0x10000); FaultCode code = messageFault.Code; if (version.Envelope == EnvelopeVersion.Soap11) { subCode = code; } else { if (version.Envelope != EnvelopeVersion.Soap12) { throw Fx.AssertAndThrow("Unsupported version."); } subCode = code.SubCode; } if (subCode != null) { if ((subCode.Namespace == WsrmIndex.GetNamespaceString(reliableMessagingVersion)) && (subCode.Name == "CreateSequenceRefused")) { string safeReasonText = FaultException.GetSafeReasonText(messageFault); if (version.Envelope == EnvelopeVersion.Soap12) { FaultCode code3 = subCode.SubCode; if (((code3 != null) && (code3.Namespace == "http://schemas.microsoft.com/ws/2006/05/rm")) && (code3.Name == "ConnectionLimitReached")) { return(new ServerTooBusyException(safeReasonText)); } if (code.IsSenderFault) { return(new ProtocolException(safeReasonText)); } } return(new CommunicationException(safeReasonText)); } if ((subCode.Namespace == version.Addressing.Namespace) && (subCode.Name == "EndpointUnavailable")) { return(new EndpointNotFoundException(FaultException.GetSafeReasonText(messageFault))); } } FaultConverter property = innerChannel.GetProperty <FaultConverter>(); if (property == null) { property = FaultConverter.GetDefaultFaultConverter(version); } if (property.TryCreateException(message, messageFault, out exception)) { return(exception); } return(new ProtocolException(System.ServiceModel.SR.GetString("UnrecognizedFaultReceivedOnOpen", new object[] { messageFault.Code.Namespace, messageFault.Code.Name, FaultException.GetSafeReasonText(messageFault) }))); }
protected bool TryGetSecurityFaultException(Message faultMessage, out Exception faultException) { faultException = null; if (!faultMessage.IsFault) { return(false); } MessageFault fault = MessageFault.CreateFault(faultMessage, 0x4000); faultException = System.ServiceModel.Security.SecurityUtils.CreateSecurityFaultException(fault); return(true); }
protected bool TryGetSecurityFaultException(Message faultMessage, out Exception faultException) { faultException = null; if (!faultMessage.IsFault) { return(false); } MessageFault fault = MessageFault.CreateFault(faultMessage, TransportDefaults.MaxSecurityFaultSize); faultException = SecurityUtils.CreateSecurityFaultException(fault); return(true); }
public static Message CreateMessage(MessageVersion version, FaultCode faultCode, string reason, object detail, string action) { if (version == null) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("version")); } if (faultCode == null) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("faultCode")); } if (reason == null) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("reason")); } return(CreateMessage(version, MessageFault.CreateFault(faultCode, new FaultReason(reason), detail), action)); }
void ValidateResponse(Message response) { if (response != null) { if (response.Version == MessageVersion.None && response is NullMessage) { response.Close(); return; } Exception innerException = null; if (response.IsFault) { try { MessageFault messageFault = MessageFault.CreateFault(response, TransportDefaults.MaxFaultSize); innerException = new FaultException(messageFault); } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } if (e is CommunicationException || e is TimeoutException || e is XmlException || e is IOException) { innerException = e; // expected exception generating fault } else { throw; } } } throw TraceUtility.ThrowHelperError( new ProtocolException(SR.GetString(SR.OneWayUnexpectedResponse), innerException), response); } }
internal static Message CreateEndpointNotFoundFault(MessageVersion version, string reason) { FaultCode code2; FaultCode subCode = new FaultCode("EndpointUnavailable", version.Addressing.Namespace); if (version.Envelope == EnvelopeVersion.Soap11) { code2 = subCode; } else { if (version.Envelope != EnvelopeVersion.Soap12) { throw Fx.AssertAndThrow("Unsupported version."); } code2 = FaultCode.CreateSenderFaultCode(subCode); } FaultReason reason2 = new FaultReason(reason, CultureInfo.CurrentCulture); MessageFault fault = MessageFault.CreateFault(code2, reason2); return(Message.CreateMessage(version, fault, version.Addressing.DefaultFaultAction)); }
protected override void ProcessReply(Message msg, TimeSpan timeout) { if (msg == null) { throw new ArgumentNullException("msg"); } // Handle DestinationUnreacheable as 400 (it is what .NET does). if (msg.IsFault) { // FIXME: isn't there any better way? var mb = msg.CreateBufferedCopy(0x10000); var fault = MessageFault.CreateFault(mb.CreateMessage(), 0x10000); if (fault.Code.Name == "DestinationUnreachable") { ctx.Response.StatusCode = 400; return; } else { msg = mb.CreateMessage(); } } // FIXME: should this be done here? if (channel.MessageVersion.Addressing.Equals(AddressingVersion.None)) { msg.Headers.Action = null; // prohibited } MemoryStream ms = new MemoryStream(); channel.Encoder.WriteMessage(msg, ms); ctx.Response.ContentType = channel.Encoder.ContentType; string pname = HttpResponseMessageProperty.Name; bool suppressEntityBody = false; if (msg.Properties.ContainsKey(pname)) { HttpResponseMessageProperty hp = (HttpResponseMessageProperty)msg.Properties [pname]; string contentType = hp.Headers ["Content-Type"]; if (contentType != null) { ctx.Response.ContentType = contentType; } ctx.Response.Headers.Add(hp.Headers); if (hp.StatusCode != default(HttpStatusCode)) { ctx.Response.StatusCode = (int)hp.StatusCode; } ctx.Response.StatusDescription = hp.StatusDescription; if (hp.SuppressEntityBody) { suppressEntityBody = true; } } if (!suppressEntityBody) { ctx.Response.ContentLength64 = ms.Length; ctx.Response.OutputStream.Write(ms.GetBuffer(), 0, (int)ms.Length); ctx.Response.OutputStream.Flush(); } }