我的Python SOAPpy webservice调用出了什么问题?

时间:2009-03-24 21:23:21

标签: python wsdl soappy

我正在尝试使用Python解释器中的以下代码调用简单的SOAP Web服务:

from SOAPpy import WSDL
wsdl = "http://www.webservicex.net/whois.asmx?wsdl"
proxy = WSDL.Proxy(wsdl)
proxy.soapproxy.config.dumpSOAPOut=1
proxy.soapproxy.config.dumpSOAPIn=1
proxy.GetWhoIS(HostName="google.com")

(是的,我是Python的新手,正在做潜水游戏......)

对GetWhoIS方法的调用失败 - 否则我猜不会在这里问。 这是我传出的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>
    <GetWhoIS SOAP-ENC:root="1">
      <HostName xsi:type="xsd:string">google.com</HostName>
    </GetWhoIS>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

这是传入的回应。

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <soap:Fault>
      <faultcode>soap:Server</faultcode>
      <faultstring>
           System.Web.Services.Protocols.SoapException:
           Server was unable to process request. ---&gt;
           System.ArgumentNullException: Value cannot be null.
         at whois.whois.GetWhoIS(String HostName)
         --- End of inner exception stack trace ---
      </faultstring>
      <detail />
    </soap:Fault>
  </soap:Body>
</soap:Envelope>

(手动格式化以便于阅读)

谁能告诉我我做错了什么?

理想情况下,无论是使用SOAPpy还是SOAP消息不正确。

谢谢!

4 个答案:

答案 0 :(得分:3)

您的通话对我来说似乎没问题,我认为这可能是一个问题太严重或配置错误的服务器(虽然我没有仔细检查过)。

本文档还提出了soappy和webservicex.net之间的不兼容性: http://users.jyu.fi/~mweber/teaching/ITKS545/exercises/ex5.pdf

在这个具体案例中,我将如何解决这个问题?

import urllib

url_handle = urllib.urlopen( "http://www.webservicex.net/whois.asmx/GetWhoIS?HostName=%s" \
                             % ("www.google.com") )
print url_handle.read()

答案 1 :(得分:2)

如@ChristopheD所述,对于某些WDSL配置,SOAPpy似乎有些错误。

我尝试使用suds(在Ubuntu上使用sudo easy_install suds),而是第一次使用。

from suds.client import Client
client = Client('http://www.webservicex.net/whois.asmx?wsdl')
client.service.run_GetWhoIS(HostName="google.com")

工作很好'联合国

答案 2 :(得分:1)

由于某种原因,客户端使用几乎从不再使用的过时表单发送请求(“SOAP Section 5编码”)。你可以根据这个来判断:

SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"

但是基于WSDL,该服务只接受常规SOAP消息。因此,很可能在您正在使用的SOAP库的WSDL解析部分出现问题。

答案 3 :(得分:0)

请检查我对另一个问题here的回答。 .net要求soap操作前面有名称空间。