如何删除 来自SOAP请求

问题描述 投票:1回答:2

我正在使用第三方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. 试图通过编写一个类并覆盖MustUnderstand属性将mustUnderstand重置为0,然后接受XML。

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

任何建议都非常感谢。

c# xml soap wcf-binding soap-client
2个回答
0
投票

我验证了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>​

0
投票

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

    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);
© www.soinside.com 2019 - 2024. All rights reserved.