views:

1431

answers:

4

I am playing around trying to call a simple SOAP webservice using the following code in the Python interpreter:

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

The call to the GetWhoIS method fails - otherwise I wouldn't be asking here, I guess. Here's my 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"&gt;
  <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"&gt;
  <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.

Thanks!

+1  A: 

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

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()
ChristopheD
A: 

As mentioned by @ChristopheD, SOAPpy seems to be buggy for certain configurations of WDSL.

I tried using suds (sudo easy_install suds on Ubuntu) instead, worked first time.

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.

Brabster
A: 

For some reason the client is sending the request using an outdated form that is almost never used anymore ("SOAP Section 5 encoding"). 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. So, most likely something is wrong in the WSDL parsing part of the SOAP library you are using.

Eugene Osovetsky
A: 

Please check my answer to another question here. .net requires the soap action have the name space prepended.

sfossen