且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

“未找到 Action 标头"使用 SOAP 网络服务时的错误消息

更新时间:2023-08-21 14:36:22

我们在基于 ASP.NET 的服务器上遇到了同样的问题(使用 python/suds 时出现错误消息,同样的查询在 SoapUi 中工作);经过大量挖掘,我们发现我们需要添加一个包含操作的 SOAP 标头(作为 XML 元素);在 Content-Type 或 SOAPAction 标头中包含操作是不够的(但也不会造成伤害).这是一个成功查询的示例(来自 SoapUi):

We had the same problem with an ASP.NET-based server (error message when using python/suds, same query worked in SoapUi); after a lot of digging, we found that we need to add a SOAP header (as XML element) which contains the action; having the action in the Content-Type or SOAPAction headers was not enough (but does not hurt either). Here's an example of a successful query (from SoapUi):

<SOAP-ENV:Envelope xmlns:ns0="..." xmlns:ns1="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope">
   <SOAP-ENV:Header xmlns:wsa="http://www.w3.org/2005/08/addressing"><wsa:Action>http://www.foo.com/.../SomeJob/getParameters</wsa:Action></SOAP-ENV:Header>
   <ns1:Body>
      <ns0:getParameters>...</ns0:getParameters>
   </ns1:Body>
</SOAP-ENV:Envelope>

使用 Python 和 SUDS,我们是这样做的:

With Python and SUDS, this is how we did it:

from suds.sax.element import Element
wsans = ('wsa', "http://www.w3.org/2005/08/addressing")
client.set_options(soapheaders = Element('Action', ns=wsans).setText(action))

action 可以从方法中查询,即如果你想调用一个方法 client.service.foo,使用

The action can be queried from the method, i.e. if you want to call a method client.service.foo, use

action = client.service.foo.method.soap.action

我们通过查看 SoapUi HTTP 日志发现了这一点.(我们也尝试过 Wireshark,但这不起作用,因为我们正在尝试使用我们不拥有的 https 服务器.)

We found this by looking at the SoapUi HTTP log. (We also tried Wireshark, but that would not work because we're trying to use an https server which we don't own.)