【问题标题】:How to read, alter, and update back the item values inside <soapenv: Body> tag in AfterReceiveRequest() method如何在 AfterReceiveRequest() 方法中读取、更改和更新 <soapenv: Body> 标记内的项目值
【发布时间】:2018-06-30 19:53:03
【问题描述】:

我现在正在实现IDispatchMessageInspector接口的AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext)方法来拦截WCFSOAP消息。

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>

我想读取并更改&lt;tem:item1&gt;&lt;/tem:item1&gt; &lt;tem:item2&gt;&lt;/tem:item2&gt; 的值并更新回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>

【问题讨论】:

  • 如果你想调整soap XML消息的结构,你需要使用MessageContract。
  • 您有什么问题?阅读或更改信息。
  • 阅读和更新
  • 显示你目前拥有的代码。

标签: c# wcf soap interceptor idispatchmessageinspector


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-22
    • 1970-01-01
    • 2013-12-14
    • 1970-01-01
    • 2011-03-01
    相关资源
    最近更新 更多