如何在AfterReceiveRequest()方法中读取,更改和更新<soapenv:body =“”>标记内的项值

时间:2018-01-22 08:20:57

标签: c# wcf soap interceptor idispatchmessageinspector

我现在正在实施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>

1 个答案:

答案 0 :(得分:0)

这篇文章介绍了在Dispatcher级别处理它的方法,它将允许您拦截所有传入的消息。你只需要仔细理解和阅读它。 https://weblogs.asp.net/paolopia/writing-a-wcf-message-inspector