我有一个 WCF 服务,我正在更改肯定响应的前缀,但是在错误响应中,只有部分消息被更改。
<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 是正确的语法,但是您可以在记录错误时看到前缀是s:
.
正在做这项工作的班级在这里
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");
}
}
我也需要去掉这个的命名空间。
我尝试了各种各样的东西,但都没有奏效。
下面是其中一种方法的示例\我尝试过的事情
protected override void OnWriteDetail(XmlDictionaryWriter writer)
{
writer.WriteStartElement("Fault", "http://schemas.xmlsoap.org/soap/envelope/");
}
但是,这不适合覆盖
看过这里的一些文档https://docs.microsoft.com/en-us/dotnet/api/system.servicemodel.channels.messagefault.onwritedetail?view=netframework-4.7.2我无法得到任何东西工作。
格式化故障消息的任何和所有帮助都会很大