Thursday, 22 December 2011

Perl: SOAP::Lite Simple .NET Service Call

Ever wondered how to call a .NET web service using the SOAP::Lite library?
I didn't think so, but just incase you did!....

Code Snippet
  1. #!/usr/bin/perl
  2. use SOAP::Lite 'trace', 'debug'; # adds debug and tracing to view SOAP msgs
  3. use SOAP::WSDL;
  4. use strict;
  5. use warnings;
  6.  
  7. my $soap = SOAP::Lite
  8. -> uri('http://services.aonaware.com/webservices')
  9. -> on_action( sub {sprintf '%s/%s', @_} )
  10. -> proxy('http://services.aonaware.com/DictService/DictService.asmx');
  11.  
  12.  
  13. print $soap->ServerInfo()->result;
End of Code Snippet


Key Points to note
1. Use the tracing and debugging options, this will tell you what is wrong (trust me, it will happen!)
2. URI - This is a reference to the NAMESPACE.... Simple view your WSDL or ASMX service, and view the 'targetNamespace' attribute for the base node.... This references the namespace... This is required when making SOAP calls.
3. PROXY - This is the actual URL to the service or WSDL.
4. on_action - What to do when the action is raised.... similar to an event.... In the example, its simply printing the response. I am also manually printing the response in the code... so you will see output twice.


For reference, there is a really good post here that troubleshoots these issues further.
Microsoft also did a good post here

No comments: