Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Using SOAP::Lite with a WSDL

by poj (Abbot)
on May 20, 2017 at 20:00 UTC ( [id://1190748]=note: print w/replies, xml ) Need Help??


in reply to Using SOAP::Lite with a WSDL

Not sure which part you are having trouble with but try this

#!perl use strict; use SOAP::Lite; # soap my $client = SOAP::Lite->uri('') ->proxy("loopback://"); $client->autotype(0)->readable(1); $client->outputxml(1); $client->ns("http://schemas.xmlsoap.org/soap/envelope/","soapenv"); $client->ns("http://tempuri.org/AWEService/API/WASAPI","was"); my $auth_data = { WAS_userName => 'WS_Decom', WAS_pasword => 'PASSWORD', }; my $search_data = { RACK_NAME => '', DEVICE_NAME => 'prodh20', MANUFACTURER => '', MODEL => '', ASSET_NUMBER => '', BARCODE_NUMBER => '', SERIAL_NUMBER => '', BUILDING => '', FLOOR => '', SPACE_ID => '', GRID_LOCATION => '', }; my $auth = SOAP::Data->name( "userIdentification" => $auth_data )->prefix('was'); my $search = SOAP::Data->name( "locatorSearchFieldsIdentification" => $search_data )->prefix('was'); my $response = $client->call("RunLocator", SOAP::Data->type('data' => $auth), SOAP::Data->type('data' => $search) ); #open OUT,'>','output.xml' or die "$!"; print $response; #close OUT;
poj

Replies are listed 'Best First'.
Re^2: Using SOAP::Lite with a WSDL
by lahfordie (Initiate) on May 20, 2017 at 20:59 UTC

    Thank you, poj. That introduces some namespace pieces I wasn't sure how to work with. However, replacing proxy with the API endpoint, I get this in response:

    <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http: +//schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/20 +01/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">< +soap:Body><soap:Fault><faultcode>soap:Client</faultcode><faultstring> +Server did not recognize the value of HTTP Header SOAPAction: http:// +tempuri.org/AWEService/API/WASAPI#RunLocator.</faultstring><detail /> +</soap:Fault></soap:Body></soap:Envelope>

    That is using the soap:address location from the wsdl file, as the proxy. Running it with loopback of course just spits the envelope back out. On the bright side, the envelope looks better now:

    <soapenv:Envelope soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:was="http://tempuri.org/AWEService/API/WASAPI" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soapenv:Body> <was:RunLocator> <was:userIdentification> <WAS_userName>WS_Decom</WAS_userName> <WAS_password>PASSWORD</WAS_password> </was:userIdentification> <was:locatorSearchFieldsIdentification> <DEVICE_NAME>SERVER</DEVICE_NAME> </was:locatorSearchFieldsIdentification> </was:RunLocator> </soapenv:Body> </soapenv:Envelope>

    Only issue I'm seeing with the envelope anymore is no prefix assigned to the lowest children, which will cause problems. I've corrected that issue manually, and I'm still left with the HTTP header faultstring.

      Ok, try this, it adds the prefixes and an empty header.

      #!perl use strict; use SOAP::Lite; # soap my $client = SOAP::Lite->uri('') ->proxy("loopback://"); $client->autotype(0)->readable(1); $client->outputxml(1); $client->ns("http://schemas.xmlsoap.org/soap/envelope/","soapenv"); $client->ns("http://tempuri.org/AWEService/API/WASAPI","was"); my %auth = ( WAS_userName => 'WS_Decom', WAS_password => 'PASSWORD', ); my %search = ( DEVICE_NAME => 'prodh20', RACK_NAME => '', # etc ); my @auth_data; for (keys %auth){ my $data = SOAP::Data->name( $_ => $auth{$_} )->prefix('was'); push @auth_data, SOAP::Data->type('data' => $data), } my @search_data; for (keys %search){ my $data = SOAP::Data->name( $_ => $search{$_} )->prefix('was'); push @search_data, SOAP::Data->type('data' => $data), } my $auth = SOAP::Data->name( "userIdentification" => \@auth_data )->prefix('was'); my $search = SOAP::Data->name( "locatorSearchFieldsIdentification" => \@search_data )->prefix('was'); my $header = SOAP::Data->type('xml' => ''); my $response = $client->call("RunLocator", SOAP::Header->type('data'=>$header), SOAP::Data->type('data' => $auth), SOAP::Data->type('data' => $search) ); #open OUT,'>','output.xml' or die "$!"; print $response; #close OUT;
      poj

        Awesome! It's working now after a slight modification from this version. I figured out that the faultstring is because I needed an on_action sub to replace the # with a slash.

        my $client = SOAP::Lite ->proxy('https://www.example.com/WAS/API/AWEService.asmx?ENDPOINT' +) ->on_action(sub { join '/', @_ }) ->outputxml(1) ->ns('http://tempuri.org/AWEService/API/WASAPI','was');

        Now to continue my Perl studies so that I can better understand what else is going on in the SOAP::Lite doc, should I have the misfortune of working with SOAP again.

        Thank you, enlightened monk!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1190748]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-04-19 07:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found