Skip to content

Commit

Permalink
Write faultactor after faultstring (otherwise the SOAP Fault message …
Browse files Browse the repository at this point in the history
…is invalid)
  • Loading branch information
Alessandro Strada committed Jan 14, 2025
1 parent 0a1e4ea commit 402e613
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/SoapCore/FaultBodyWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
WriteSoap11Fault(writer);
}
else
{
// We will default to the oldest SOAP format instead of
// breaking everything
{
// We will default to the oldest SOAP format instead of
// breaking everything
WriteSoap11Fault(writer);
}
}

private void WriteSoap12Fault(XmlDictionaryWriter writer)
{
// NOTE: This default culture is a hack until a better localisation solution is
// built. At this stage it assumes the current thread culture
{
// NOTE: This default culture is a hack until a better localisation solution is
// built. At this stage it assumes the current thread culture
var defaultCulture = CultureInfo.CurrentCulture;

var faultString = _faultStringOverride ?? (_exception.InnerException != null ? _exception.InnerException.Message : _exception.Message);
Expand Down Expand Up @@ -81,8 +81,8 @@ private void WriteSoap11Fault(XmlDictionaryWriter writer)
var faultString = _faultStringOverride ?? (_exception.InnerException != null ? _exception.InnerException.Message : _exception.Message);
var faultDetail = ExtractFaultDetailsAsXmlElement(_exception);

writer.WriteStartElement("Fault", Namespaces.SOAP11_ENVELOPE_NS);

writer.WriteStartElement("Fault", Namespaces.SOAP11_ENVELOPE_NS);

/* SUPPORT FOR SPECIFYING CUSTOM FAULTCODE AND NAMESPACE
For Example, this would result in the response below:
Expand All @@ -106,7 +106,8 @@ private void WriteSoap11Fault(XmlDictionaryWriter writer)
</s:Fault>
</s:Body>
</s:Envelope>
*/
*/
var actor = default(string);
if (_exception is FaultException)
{
var faultException = (FaultException)_exception;
Expand All @@ -126,18 +127,19 @@ private void WriteSoap11Fault(XmlDictionaryWriter writer)
writer.WriteElementString("faultcode", "s:Client");
}

var actor = faultException.CreateMessageFault()?.Actor;
if (!string.IsNullOrWhiteSpace(actor))
{
writer.WriteElementString ("faultactor", actor);
}
actor = faultException.CreateMessageFault()?.Actor;
}
else
{
writer.WriteElementString("faultcode", "s:Client");
}

writer.WriteElementString("faultstring", faultString);

if (!string.IsNullOrWhiteSpace(actor))
{
writer.WriteElementString("faultactor", actor);
}

if (faultDetail != null)
{
Expand Down Expand Up @@ -165,8 +167,8 @@ private XmlElement ExtractFaultDetailsAsXmlElement(Exception ex)
var doc = new XmlDocument();
doc.Load(ms);
return doc.DocumentElement;
}

}

/// <summary>
/// Helper to extract object of a detailed fault.
/// </summary>
Expand Down

0 comments on commit 402e613

Please sign in to comment.