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

Hello all,

The WSDL that I use was enhanced with security. (We're the lowest test environment, so it was inevitable). I had my WSDL connector working like a charm before the "enhancement", but now I am at a loss on how to pass the userID and password via a HTTP header. Here is my code thus far:

#!/usr/bin/perl ############################# # Written By: Frank Friedman # Email: frank.e.friedman@jpmchase.com # Date: Aug. 15, 2012 # Summary: ############################# use Data::Dumper; use SOAP::Lite +trace => 'debug'; #use SOAP::Lite; #use JPMC::PIDM; #use Getopt::Std; #use File::Spec; #use Log::Log4perl qw(get_logger :no_extra_logdie_message); use jpmc_wsdl; #my $proxy = 'http://TEST:testing@myid-dev.company.net/rjam-request-se +rvice/svc/RequestService/3?wsdl'; my $proxy = 'http://myid-dev.company.net/rjam-request-service/svc/Requ +estService/3?wsdl'; my $xmlns = "http://myid.company.net/request/service/3"; my $provider = "homeFolderWin"; my $maxLockedTimes=200; my $startingRecord = "1"; my $recordsToRetrieve = "1"; ## Local variables my $action = "setBestMatch"; my $state = "PLACED"; my $recordCount=0; my $response = fetchandlock({ proxy => $proxy, xmlns => $xmlns, first => $startingRecord, max => $recordsToRetrieve, action => $action, state => $state, }); if($response->fault) { $tmp_string = $response->faultstring(); exit; } #=============================== # Password = test = VEVTVElORzp0ZXN0 # userID = TESTING sub fetchandlock { my $zID="TEST"; my $zPW="VEVTVElORzp2ZXN0"; #base 64 encoding my ($args) = @_; # IIS web services expect / as a separator for uri and method. my $lite = SOAP::Lite->new()->on_action(sub { join '/', @_ } ) ->proxy($args->{proxy}); my $response = $lite->call( SOAP::Data->name('fetchAndLock') ->attr({ 'xmlns', $args->{xmlns}}), SOAP::Data->name("first")->value($args->{first}), SOAP::Data->name("max")->value($args->{max}), SOAP::Data->name("action")->value($args->{action}), SOAP::Data->name("state")->value($args->{state}), ); return $response; }

I can easily connect to the WSDL if I put the userID and password in the proxy (note the commented out "proxy" line near the top).

any insight on how to do it via a SOAP call? I know it goes in my "fetchandLock" subroutine, but where and how do I code it?

any help/insight/suggestions/etc... would be greatly appreciated.

Frank

Replies are listed 'Best First'.
Re: soap::lite and authorization
by Anonymous Monk on Aug 28, 2012 at 02:21 UTC
      ok. I have attempted to put in this piece of code. Here is what I tried:
      my $lite = SOAP::Lite->new()->on_action(sub { join '/', @_ } ) ->proxy($args->{proxy}); my $response = $lite->call( SOAP::Data->name('fetchAndLock') ->attr({ 'xmlns', $args->{xmlns}}), SOAP::Data->name("first")->value($args->{first}), SOAP::Data->name("max")->value($args->{max}), SOAP::Data->name("action")->value($args->action}), SOAP::Data->name("state")->value($args->{state}), ); return $response; } sub SOAP::Transport::HTTP::Client::get_basic_credentials { $zID => $zPW; }

      Where $zID and $zPW were defined higher up in the code. When I run the script, I receive the following error:

      SOAP::Transport::HTTP::Client::send_receive: HTTP/1.1 401
      Unauthorized
      Connection: close
      Date: Wed, 29 Aug 2012 14:16:22 GMT
      Server: IBM_HTTP_Server
      Content-Language: en-US
      Content-Type: text/xml; charset=UTF-8
      Client-Date: Wed, 29 Aug 2012 14:16:22 GMT
      Client-Peer: 169.81.175.20:80
      Client-Response-Num: 1
      Client-Transfer-Encoding: chunked
      Client-Warning: Missing Authenticate header


      I tried putting the "get_basic_credentials" line just after the "my $line = SOAP..." line, but the error is the same.

      where am I going wrong? Any help/advice/suggestions/etc... are much appreciated.

      Thanks
      Frank

        where am I going wrong? Any help/advice/suggestions/etc... are much appreciated.

        At I suspect you provided a base64 encoded password, but transport.... takes care of any required encoding