如何在使用soappy发出soap请求时添加头

2024-04-26 03:53:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个WSDL文件,使用它我想要发出soap请求,它看起来就像这样--

<?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>

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

^{pr2}$

我得到这个错误

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文件有一些错误。 现在,有人能建议我如何将头添加到这个传出的soap请求中吗。在

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


Tags: orgenvhttpstringwwwbodyschemassoap
1条回答
网友
1楼 · 发布于 2024-04-26 03:53:00

未测试,但我相信您可以使用the docssuggest方法添加soap头,即创建并准备一个SOAPpy.Header实例,然后使用server = server._hd (hd)获得一个配备了它的代理(尽管在您的案例中,这似乎是一个破坏WSDL的变通方法,正如您所说,修复WSDL可能更好吗?)。在

相关问题 更多 >

    热门问题