如何在 Zeep 中创建自定义标题

问题描述

Zeep 和 SOAP 的全新功能

我希望我的 SOAP 请求在 SOAP 信封中包含标头。 示例 SOAP 看起来像

<saop:Envelope>
<soap:Header
   xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
   xmlns:wsa="http://www.w3.org/2005/08/addressing"
   xmlns:wst="http://schemas.xmlsoap.org/ws/2005/02/trust"
   xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
   xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
   xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

   <wsa:Action S:mustUnderstand="1" wsu:Id="Action"
      xmlns:S="S">http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/RetrieveMultiple
   </wsa:Action>

</soap:Header>
</saop:Envelope>

我尝试在 ZEEP 中创建自定义 SOAP 标头,但遇到了问题 <Action></Action> 标记可以使用以下代码生成

header_1 = xsd.Element(
    '{http://www.w3.org/2005/08/addressing}Action',xsd.ComplexType([
        xsd.Attribute(
            '{S}mustUnderstand',xsd.String()
        ),xsd.Attribute(
            '{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd}Id',])
)

header_value = header_1(mustUnderstand='1',Id='Action')

但这给出了输出

<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
  <soap-env:Header>
    <ns0:Action xmlns:ns0="http://www.w3.org/2005/08/addressing" xmlns:ns1="S" xmlns:ns2="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" ns1:mustUnderstand="1" ns2:Id="Action"/>
  </soap-env:Header>
</soap-env:Envelope>

如何编辑它以获取 http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/RetrieveMultiple 标签内的 <Action></Action> 内容? 任何帮助将不胜感激。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)