问题描述
我正在使用消息检查器来设置消息正文
I am using message inspector to vlaidate the Message body
这是我的代码
void ValidateMessageBody( 参考 System.ServiceModel.Channels. Message 消息, 布尔 isRequest)
void ValidateMessageBody(ref System.ServiceModel.Channels.Message message,bool isRequest)
{
如果 (!message.IsFault)
if (!message.IsFault)
{
尝试
{
XmlDictionaryReaderQuotas 配额= 新 XmlDictionaryReaderQuotas ();
XmlDictionaryReaderQuotas quotas =newXmlDictionaryReaderQuotas();
XmlReader bodyReader = message.GetReaderAtBodyContents().ReadSubtree();
XmlReader bodyReader = message.GetReaderAtBodyContents().ReadSubtree();
XmlReaderSettings wrapperSettings = 新 XmlReaderSettings ();
XmlReaderSettings wrapperSettings =newXmlReaderSettings();
wrapperSettings.CloseInput =
wrapperSettings.CloseInput =
真 ;
true;
wrapperSettings.Schemas = schemaSet;
wrapperSettings.Schemas = schemaSet;
wrapperSettings.ValidationFlags =
wrapperSettings.ValidationFlags =
XmlSchemaValidationFlags .None;
XmlSchemaValidationFlags.None;
wrapperSettings.ValidationType =
wrapperSettings.ValidationType =
ValidationType .Schema;
ValidationType.Schema;
wrapperSettings.ValidationEventHandler + =
wrapperSettings.ValidationEventHandler +=
新 ValidationEventHandler (InspectionValidationHandler);
newValidationEventHandler(InspectionValidationHandler);
XmlReader wrappedReader = XmlReader .Create(bodyReader,wrapperSettings);
XmlReader wrappedReader =XmlReader.Create(bodyReader, wrapperSettings);
//将正文放入支持内存的编写器中验证
此 .isRequest = isRequest;
this.isRequest = isRequest;
MemoryStream memStream = 新 MemoryStream ();
MemoryStream memStream =newMemoryStream();
XmlDictionaryWriter xdw = XmlDictionaryWriter .CreateBinaryWriter(memStream);
XmlDictionaryWriter xdw =XmlDictionaryWriter.CreateBinaryWriter(memStream);
xdw.WriteNode(wrappedReader,
xdw.WriteNode(wrappedReader,
false );
false);
xdw.Flush(); memStream.Position = 0;
xdw.Flush(); memStream.Position = 0;
XmlDictionaryReader xdr = XmlDictionaryReader .CreateBinaryReader(memStream,quota);
XmlDictionaryReader xdr =XmlDictionaryReader.CreateBinaryReader(memStream, quotas);
//使用经过验证的正文重建邮件
消息 replaceMessage = 消息 .CreateMessage(message.Version, 空 ,xdr);
Message replacedMessage =Message.CreateMessage(message.Version,null, xdr);
replacedMessage.Headers.CopyHeadersFrom(message.Headers);
replacedMessage.Headers.CopyHeadersFrom(message.Headers);
replacedMessage.Properties.CopyProperties(message.Properties);
replacedMessage.Properties.CopyProperties(message.Properties);
消息=替换消息;
}
捕获 ( 异常 例如)
catch (Exception ex)
{
扔 新 GenericException ( SharedUtil .CurrentMemberName, 前任);
thrownewGenericException(SharedUtil.CurrentMemberName, ex);
}
}
}
输出结果如下:
推荐答案
谢谢您的发帖!我建议在( NET Framework开发人员中心 > .NET开发论坛 > Windows Communication Foundation )论坛位于: ( http://social.msdn.microsoft.com/Forums/en-US/wcf/threads ).
Thank you for your post! I would suggest creating a new thread for your question in the (NET Framework Developer Center >.NET Development Forums> Windows Communication Foundation) forum located here: (http://social.msdn.microsoft.com/Forums/en-US/wcf/threads).
希望对您有所帮助.
Hope that would be helpful.
祝你有美好的一天!
Have a great day!
谢谢&问候
Thanks & regards,
这篇关于WCf邮件检查器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!