Friday, 23 December 2011

WSDL and SOAP: Test and Invoke WSDL online!

Really good website for service discovery
http://www.service-repository.com

They also have a WSDL tester and invoker... displays the SOAP messages and response. It also builds the HTML forms dynamically. Great stuff!
http://www.service-repository.com/client/start

Thursday, 22 December 2011

Perl: SOAP::Lite - 500 Can't connect to webservice.service.com:443 (Invalid argument) https

I had a problem recently with trying to call a HTTPS Web Service using Perl's SOAP::Lite library, and I was receiving this error:
"500 Can't connect to webservice.service.com:443 (Invalid argument)"...

Note: Port 443 ssl. This is the default port for HTTPS/SSL. This is the encrypted form of HTTP that normally runs over port 80.

Okay, so problem identified... Cannot communicate with service over 443... What next?

We use cpan to install another library called "Crypt::SSLeay"... sounds spooky! But don't worry, it simply provides support for the HTTPS protocol in LWP (Library for WWW in Perl).

cpan - what the heck? View my previous post on cpan here

Simply issue this command, and cpan will do the rest...
Code Snippet
  1. sudo perl -MCPAN -e "install Crypt::SSLeay"
End of Code Snippet

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

Perl: Can't locate [Library Here] in @INC - (CPAN Usage)

So i've been looking into Perl this week and I came across an error... quite simple when you know how... this post explains in !English! the options you can take to tackle this... CPAN is utilised and explained in this post.


The Error
SeanMAC:tmp localhome$ perl test.pl
Can't locate SOAP/Lite.pm in @INC (@INC contains: /Library/Perl/Updates/5.8.8/darwin-thread-multi-2level /Library/Perl/Updates/5.8.8 /System/Library/Perl/5.8.8/darwin-thread-multi-2level /System/Library/Perl/5.8.8 /Library/Perl/5.8.8/darwin-thread-multi-2level /Library/Perl/5.8.8 /Library/Perl /Network/Library/Perl/5.8.8/darwin-thread-multi-2level /Network/Library/Perl/5.8.8 /Network/Library/Perl /System/Library/Perl/Extras/5.8.8/darwin-thread-multi-2level /System/Library/Perl/Extras/5.8.8 /Library/Perl/5.8.6 /Library/Perl/5.8.1 .) at test.pl line 17.
BEGIN failed--compilation aborted at test.pl line 17.



So I created a test script and attempted to execute it. It threw up an error at Line 17 complaining that I didn't have the SOAP::Lite library. I.e. "Can't locate SOAP/Lite.pm"

In .NET we would probably either Google the library or use NuGet (NuGet.org - NuGet is a Visual Studio extension that makes it easy to install and update open source libraries).

If we would ever try to compare Perl to the .NET world, we could relate CPAN to NuGet in terms of what it does for us. That is, gets third party libraries, unpacks them and installs them for us.


CPAN
CPAN, the Comprehensive Perl Archive Network, is an archive of over 100,000 modules of software written in Perl, as well as documentation for it.

To use cpan, open up a terminal or command window, and use the following command. This will run cpan as ROOT user. This is sometimes necessary as it requires access to shared library directories.
Code Snippet
  1. perl -MCPAN -e 'shell'
End of Code Snippet

You will then be in the cpan shell. Type 'h' for help....

commandargumentdescription
a,b,d,mWORD or /REGEXP/ about authors, bundles, distributions, modules
iWORD or /REGEXP/ about anything of above
rNONEreinstall recommendations
lsAUTHORabout files in the author's directory
getdownload
makemake (implies get)
testMODULESmake test (implies make)
installDISTS, BUNDLESmake install (implies test)
cleanmake clean
lookopen subshell in these dists' directories
readmedisplay these dists' README files


If we wish to install our library (This includes get/download, make, test and install) then we simply issue the command....
Code Snippet
  1. install [Library Name]
End of Code Snippet

with example
Code Snippet
  1. install SOAP::Lite
End of Code Snippet

You will be asked a few options, mostly regarding ideal location to download from, connection timeouts etc... You can simply keep hitting enter to use the defaults.

If all is successful, your library will be installed and included within the @INC array (Containing paths to libraries used by Perl).

Happy Scripting!

Friday, 9 December 2011

iOS - Viewing hidden files and directories

Write the following into a terminal window....

Code Snippet
  1. defaults write com.apple.finder AppleShowAllFiles TRUE
  2. killall Finder
End of Code Snippet

This will show you all of the hidden files and folders on your operating system. If you want to reverse the command replace TRUE with FALSE.