我现在正在实施AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext)
接口的IDispatchMessageInspector
方法来拦截WCF
SOAP
消息。
System.ServiceModel.Channels.Message request
如下
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header>
<To soapenv:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://localhost:8993/TLS.svc/soap</To>
<Action soapenv:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/TLS/GetMerchant</Action>
</soapenv:Header>
<soapenv:Body>
<tem:GetMerchant>
<tem:item1>value1</tem:item1>
<tem:item2>value2</tem:item2>
</tem:GetMerchant>
</soapenv:Body>
</soapenv:Envelope>
我想阅读并更改<tem:item1></tem:item1>
<tem:item2></tem:item2>
的值,并在不损坏其他邮件原始属性的情况下更新回System.ServiceModel.Channels.Message request
<soapenv:Envelope ... >
<soapenv:Header>
<To soapenv:mustUnderstand="1" ... </To>
<Action soapenv:mustUnderstand="1" ... </Action>
</soapenv:Header>
<soapenv:Body>
<tem:GetMerchant>
<tem:item1>Updatedvalue1</tem:item1>
<tem:item2>Updatedvalue2</tem:item2>
</tem:GetMerchant>
</soapenv:Body>
</soapenv:Envelope>
答案 0 :(得分:0)
这篇文章介绍了在Dispatcher级别处理它的方法,它将允许您拦截所有传入的消息。你只需要仔细理解和阅读它。 https://weblogs.asp.net/paolopia/writing-a-wcf-message-inspector