简体   繁体   English

我的 Python SOAPpy Web 服务调用有什么问题?

[英]What's wrong with my Python SOAPpy webservice call?

I am playing around trying to call a simple SOAP webservice using the following code in the Python interpreter:我正在尝试使用 Python 解释器中的以下代码来调用简单的 SOAP 网络服务:

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")

(Yep, I'm new to Python, doing the diveintopython thing...) (是的,我是 Python 的新手,正在做 Diveintopython 的事情......)

The call to the GetWhoIS method fails - otherwise I wouldn't be asking here, I guess.对 GetWhoIS 方法的调用失败 - 否则我不会在这里问,我猜。 Here's my outgoing SOAP:这是我即将传出的 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>

And here's the incoming response.这是传入的响应。

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

(manually formatted for easier reading) (手动格式化以便于阅读)

Can anyone tell me what am I doing wrong?谁能告诉我我做错了什么?

Ideally both in terms of use of SOAPpy, and why the SOAP message is incorrect.理想情况下,无论是就 SOAPpy 的使用而言,还是 SOAP 消息不正确的原因。

Thanks!谢谢!

Your call seems all right to me, i think this could be a soappy problem or misconfigured server (although i have not checked this thoroughly).你的电话对我来说似乎没问题,我认为这可能是一个肥皂问题或错误配置的服务器(尽管我没有彻底检查过)。

This document also suggests incompatibilities between soappy and webservicex.net: http://users.jyu.fi/~mweber/teaching/ITKS545/exercises/ex5.pdf该文档还暗示了 soappy 和 webservicex.net 之间的不兼容性: http://users.jyu.fi/~mweber/teaching/ITKS545/exercises/ex5.pdf

How i would work around this in this specific case?在这种特定情况下,我将如何解决这个问题?

import urllib

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

As mentioned by @ChristopheD, SOAPpy seems to be buggy for certain configurations of WDSL.正如@ChristopheD 所提到的,SOAPpy 似乎对于 WDSL 的某些配置有问题。

I tried using suds (sudo easy_install suds on Ubuntu) instead, worked first time.我尝试使用 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")

Job's a good 'un.乔布斯是个好人。

For some reason the client is sending the request using an outdated form that is almost never used anymore ("SOAP Section 5 encoding").由于某种原因,客户端使用几乎不再使用的过时形式发送请求(“SOAP 第 5 节编码”)。 You can tell based on this:你可以根据这个来判断:

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

But based on the WSDL, the service only accepts regular SOAP messages.但是基于 WSDL,该服务只接受常规的 SOAP 消息。 So, most likely something is wrong in the WSDL parsing part of the SOAP library you are using.因此,WSDL 解析您正在使用的 SOAP 库的一部分很可能有问题。

Please check my answer to another question here .在此处查看我对另一个问题的回答。 .net requires the soap action have the name space prepended. .net 需要在 soap 操作前附加名称空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM