【问题标题】:How to remove <a:To s:mustUnderstand="1"> from SOAP Request如何从 SOAP 请求中删除 <a:To s:mustUnderstand="1">
【发布时间】:2015-09-08 04:32:50
【问题描述】:

我正在使用第三方 Duplex 服务(假设这是因为实施了回调合同)。下面是配置部分。服务抛出异常,说它无法理解请求 XML "a:To mustUnderstand="1" 中的标签。

 <endpoint address="http://vmsvalservice-uat.rpdata.com:80/vms-valuation/soap/soapws"
    binding="customBinding" bindingConfiguration="VMSSSO_CustomBinding" behaviorConfiguration="VMSSSOHeader" 
    contract="VMSSSOService.VmsPort" name="VmsPortSoap11">
  </endpoint>

<binding name="CustomBinding" receiveTimeout="00:10:00" sendTimeout="00:01:00">
<security authenticationMode="UserNameOverTransport" enableUnsecuredResponse="true" allowInsecureTransport="true"/>
<compositeDuplex clientBaseAddress="http://localhost:8080"/>
<oneWay maxAcceptedChannels ="2"></oneWay>
<textMessageEncoding messageVersion="Soap11WSAddressing10" writeEncoding="utf-8" />
<httpTransport maxBufferPoolSize="524288" maxBufferSize="524288" maxReceivedMessageSize="524288"/>
</binding>

请求 XML:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<a:MessageID>urn:uuid:76901ce5-0bab-42e2-ac76-18eddf367d25</a:MessageID>
<a:To s:mustUnderstand="1">http://vmsvalservice-uat.rpdata.com/vms-valuation/soap/soapws</a:To>
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">

我尝试了两种方法来修复它。

  1. 我已尝试 BeforeSendRequest 来控制该行为,但在调用此事件后,此标记会添加到 Soap 信封中。

  2. 尝试通过编写一个类并在接受 XML 时覆盖 MustUnderstand 属性来将 mustUnderstand 重置为 0。

无论如何我可以阻止这个标签消失或重置 MustUnderstand。

非常感谢任何建议。

【问题讨论】:

    标签: c# xml soap wcf-binding soap-client


    【解决方案1】:

    我验证了xml,发现架构需要a。您应该按以下方式验证整个 XML:从 VS 菜单:项目:添加新项目:XML 文件。将您的 XML 粘贴到窗口中,确保只有一个标识行。任何错误都会像编译器错误一样显示在错误列表中。

    <?xml version="1.0" encoding="utf-8" ?>
    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
      <s:Header>
        <a:MessageID>urn:uuid:76901ce5-0bab-42e2-ac76-18eddf367d25</a:MessageID>
        <a:To s:mustUnderstand="1">http://vmsvalservice-uat.rpdata.com/vms-valuation/soap/soapws</a:To>
        <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
        </o:Security>
      </s:Header>
      <s:Body>
      </s:Body>
    </s:Envelope>​
    

    【讨论】:

      【解决方案2】:

      实际上通过显式删除给定的标头并在之后重新插入来解决这个问题:

          newHeader = MessageHeader.CreateHeader("To", "http://www.w3.org/2005/08/addressing", m.Headers.To.ToString(), false);
          index = m.Headers.FindHeader("To", Definitions.WSA_NAMESPACE_FULL);
          m.Headers.RemoveAt(index);
          m.Headers.Insert(index, newHeader);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-05-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-04-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多