我现在正在实现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>
这篇文章描述了在调度程序级别处理它的方式,这将允许您拦截所有传入的消息。您只需要理解并仔细阅读即可。https://weblogs.asp.net/paolopia/writing-a-wcf-message-inspector