Blog
SOAP::Lite
In work I was given the task of writing an API for something. Being the old dinosaur I am I wrote it using the XMLRPC protocol. Mainly cos its simple, I've written a few using it before and Perl gives me a nice interface to it all in XML::RPC. All in all writing the API wasn't hard - using it is even easier. XMLRPC is very old but it is simple and that's why I like it. If I had more time I would have written in it with JSON-RPC but time was short and this got it done quickly, cheaply and more importantly it kept the customer happy.
The second part of this project entailed me using the API that they have. And to my horror it was using SOAP. I find SOAP very complicated to use. Maybe its a mental block I have with it. Who knows - but I am not alone in my thinking that its a huge mess to deal with. I started with SOAP::WSDL but it wasn't playing nice. I found the lack of documentation annoying. I wanted to edit certain things in the headers but found it too confusing. I said to the #cabal and Jaffs kindly pointed me in the direction of SOAP Client. In the end I reverted to using SOAP::Lite. Am sure that SOAP::WSDL could have done what I wanted but it was taking too long. So I hammered out a script really quickly then got to manipulating the headers to what SOAP Client was passing in to ensure that it worked. A very nasty way to get it to work. I found the lack of documentation and example scripts annoying. So here is mine - I kept the 'trace' on so I could see exactly what was happening.
If you are reading this and thinking of writing your own web service please don't do it in SOAP.. It makes programmers go bald!
Example Code:I plugged the above into the code and it has worked nicely since. What a waste of good hair!#!/usr/bin/perluse strict;use warnings;use SOAP::Lite +trace => 'all';my $soap = SOAP::Lite->new( proxy => 'http://xxxxxxxx.com/xxxxxxx.asmx');$soap->default_ns('http://tempuri.org/');$soap->on_action(sub { join '', @_ });my $method = SOAP::Data->name('UploadXML')->attr({xmlns => 'http://tempuri.org/'});my $date = (SOAP::Data->name('input')->value(SOAP::Data->name('DATE_PROVIDED')->value('2011-02-24')));my @param = (SOAP::Data->name('REQUEST_NUMBER')->value('1'),SOAP::Data->name('ID')->value('1'),$date,SOAP::Data->name('DATA')->value('1'),);my $run = $soap->call($method => @param);die $run->fault->{ faultstring } if ($run->fault);print $run->result, "n";
- Perl (1)
- Programming (3)
- SOAP (1)
- SOAP::Lite (1)
- SOAP::WSDL (1)
- XMLPRC (1)