I have a WCF Service where I am changing the prefix of a positive response, however on a fault response only part of the message is being changed.
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<s:Fault
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<faultcode>s:Client</faultcode>
<faultstring xml:lang="en-GB">Unable to satisfy web service request at this time.This may relate to the format or sequence of the requests, the status of the requested information or reflect a service issue.</faultstring>
</s:Fault>
</SOAP-ENV:Body>
SOAP-ENV is the correct syntax however as you can see when logging the fault the prefix is s:.
The class that is doing the work is here
public class ProposalMessage : Message
{
private readonly Message message;
public ProposalMessage(Message message)
{
this.message = message;
}
public override MessageHeaders Headers
{
get { return this.message.Headers; }
}
public override MessageProperties Properties
{
get { return this.message.Properties; }
}
public override MessageVersion Version
{
get { return this.message.Version; }
}
protected override void OnWriteStartBody(XmlDictionaryWriter writer)
{
writer.WriteStartElement("Body", "http://schemas.xmlsoap.org/soap/envelope/");
}
protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
{
this.message.WriteBodyContents(writer);
}
protected override void OnWriteStartEnvelope(XmlDictionaryWriter writer)
{
writer.WriteStartElement("SOAP-ENV", "Envelope", "http://schemas.xmlsoap.org/soap/envelope/");
writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
writer.WriteAttributeString("xmlns", "xsd", null, "http://www.w3.org/2001/XMLSchema");
}
}
and I also need to strip out the namespace of this too.
I have tried in the a variety of things, none of which have worked.
below is an example of one of the methods \ things I have tried
protected override void OnWriteDetail(XmlDictionaryWriter writer)
{
writer.WriteStartElement("Fault", "http://schemas.xmlsoap.org/soap/envelope/");
}
However this is not an suitable for overriding
Having looked at some of the documentation here https://learn.microsoft.com/en-us/dotnet/api/system.servicemodel.channels.messagefault.onwritedetail?view=netframework-4.7.2 I am unable to get anything to work.
Any and all help on formatting the fault message will be greate
You can try the following solution:
This is CustomMessage.
This is MyCustomMessageFormatter.
This is MyMessageAttribute.We add MyCustomMessageFormatter to the behavior.
We add the behavior we just defined to the method.