如何在 AfterReceiveRequest() 方法中读取、更改和更新回 <soapenv: Body> 标签中的项目值



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

相关内容

  • 没有找到相关文章

最新更新