【问题标题】:How to add header while making soap request using soappy如何在使用soappy发出soap请求时添加标头
【发布时间】:2009-09-26 14:22:13
【问题描述】:

我有 WSDL 文件,我想用它来发出一个看起来像这样的肥皂请求 --

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <AuthSoapHd xmlns="http://foobar.org/">
      <strUserName>string</strUserName>
      <strPassword>string</strPassword>
    </AuthSoapHd>
  </soap:Header>
  <soap:Body>
    <SearchQuotes xmlns="http://foobar.org/">
      <searchtxt>string</searchtxt>
    </SearchQuotes>
  </soap:Body>
</soap:Envelope>

为了解决这个问题,我这样做了

>> from SOAPpy import WSDL
 >> WSDLFILE = '/path/foo.wsdl'
 >> server = WSDL.Proxy(WSDLFILE)
 >> server.SearchQuotes('rel')

我收到这个错误

faultType: <Fault soap:Server: System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object.

我调试了它并得到了这个

*** Outgoing SOAP ******************************************************
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
  SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
  xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
  xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:xsd="http://www.w3.org/1999/XMLSchema"
>
<SOAP-ENV:Body>
<SearchQuotes SOAP-ENC:root="1">
<v1 xsi:type="xsd:string">rel</v1>
</SearchQuotes>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我们可以看到它不包含任何标题。我认为 WSDL 文件有一些错误。 现在,谁能建议我如何在这个传出的肥皂请求中添加标头。

我们将不胜感激任何形式的帮助。提前致谢

【问题讨论】:

    标签: python soap soappy


    【解决方案1】:

    未测试,但我相信您可以使用the docs 建议添加soap 标头的方法,即制作并准备一个SOAPpy.Header 实例,然后使用server = server._hd (hd) 获取配备它的代理(尽管在您的如您所说,这似乎是一种尝试破坏 WSDL 的变通方法——修复 WSDL 会更好吗?)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-10
      相关资源
      最近更新 更多