我想使用from 的BeforeSendRequest
方法“注入”自定义 XML 文本IClientMessageInspector
。这是我尝试过的代码:
public object BeforeSendRequest(ref Message request, IClientChannel channel)
{
String myXML = "somexmlcontent";
XmlDocument doc = new XmlDocument();
doc.LoadXml(myXML);
var ms = new MemoryStream();
XmlDictionaryWriter writer = XmlDictionaryWriter.CreateTextWriter(ms);
doc.WriteTo(writer);
writer.Flush();
ms.Position = 0;
XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(ms, XmlDictionaryReaderQuotas.Max);
Message newReply = Message.CreateMessage(reader, int.MaxValue, request.Version);
request = newReply;
return null;
}
但它确实返回了错误“无法识别的消息版本”。