cs3p has asked for the wisdom of the Perl Monks concerning the following question:

Hai
I am trying to access a .Net web service in perl, here is the code i have written
use SOAP::Lite +trace => all; $soap = SOAP::Lite -> uri('http://www.webservicex.net') -> on_action( sub { join '/', 'http://www.webserviceX.NET', $_[1] +} ) -> proxy('http://www.webservicex.net/globalweather.asmx'); my $method = SOAP::Data->name('GetCitiesByCountry') ->attr({xmlns => 'http://www.webserviceX.NET/'}); my $param = SOAP::Data->name("CountryName" =>"India"); $result= $soap->call($method,$param)->result();

Even though i am passing the parameter "CountryName" it gives an exception on it. I have observed that the soap requests generated by the above code are in the following format

<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:xsi="ht +tp://www.w3.org/1999/XMLSchema-instance" xmlns:SOAP-ENC="http://schem +as.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap +.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema" SOA +P-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP +-ENV:Body><GetCitiesByCountry xmlns="http://www.webserviceX.NET/"><Co +untryName xsi:type="xsd:string">India</CountryName></GetCitiesByCount +ry></SOAP-ENV:Body></SOAP-ENV:Envelope>

where as the the the example soap request is in the following format
POST /globalweather.asmx HTTP/1.1 Host: www.webservicex.net Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://www.webserviceX.NET/GetCitiesByCountry" <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" x +mlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schema +s.xmlsoap.org/soap/envelope/"> <soap:Body> <GetCitiesByCountry xmlns="http://www.webserviceX.NET"> <CountryName>string</CountryName> </GetCitiesByCountry> </soap:Body> </soap:Envelope>

Could you please help on this.. Regards, Siva

Replies are listed 'Best First'.
Re: Accessing .Net Web Service
by philcrow (Priest) on May 24, 2007 at 14:46 UTC
    It looks like the service you are hitting is expecting to use document style while you are sending rpc style. This only affects one thing in the packet. The CountryName has an xsi:type attribute, which is right for rpc, but could be confusing to a document style service.

    I don't think Soap::Lite handles document style packets, so I'm not sure what your best solution is. Document style is simple enough to do by hand. See for example Re: Dynamic Language questions. The purpose of the code in that node was to stand alone. If you adopt its approach, you will, of course, want to factor out the SOAP generation into a module (perhaps I should do that for a CPAN module like SOAP::Doc). For now I use Gantry which has that factoring.

    Phil

    The Gantry Web Framework Book is now available.
Re: Accessing .Net Web Service
by ForgotPasswordAgain (Vicar) on May 24, 2007 at 09:11 UTC
Re: Accessing .Net Web Service
by cengineer (Pilgrim) on May 24, 2007 at 14:09 UTC
    Are you using the latest version of SOAP::Lite? I had some problems using an older version, but upgrading to 0.69 solved them.