Perl and sophisticated SOAP request

I need to make a somewhat complicated soap request using Perl, preferably using SOAP::Lite . I know that the service is active and has been successful in getting errors from the other end. Here is the soap request I need to do:

 <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <GetCategories xmlns="http://webservices.uship.com"> <token>string</token> </GetCategories> </soap:Body> </soap:Envelope> 

I researched this through Google to no avail.

Refresh . Code used

 use SOAP::Lite; print SOAP::Lite -> uri('webservices.uship.com/uShipsvc.asmx?WSDL';) -> proxy('http:/webservices.uship.com') -> GetCategories('myToken') -> result; 

It returns

500 bad hostname, 500 Unable to connect to: 80 (Bad hostname '') in line soap2.pl 2

+4
source share
4 answers

In the SOAP :: Lite Getting Started Guide, your code should look something like this:

 #!perl -w use SOAP::Lite; print SOAP::Lite uri('http://www.soaplite.com/Temperatures') proxy('http://webservices.uship.com') GetCategories('string') result; 

Insert a URI for the returned object in uri()

+3
source

I had problems with SOAP calls because the server I was talking to was .NET, which apparently has problems communicating with SOAP :: Lite: http://msdn.microsoft.com/en -us / library / ms995764.aspx # soapliteperl_topic3

Even if your server is not .NET, this is another way to make your call (which works for me):

 # proxy and uri strings should NOT have trialing slashes my $_uri = 'http://youruri.com/whatever'; my $_proxy = 'http://yourproxy.com/something.asmx'; my $methodName = 'GetCategories'; my @params = ( SOAP::Data->name( 'token'=>'string' ), ); my $handle = SOAP::Lite ->uri( $_uri ) ->proxy( $_proxy , timeout => 30, keep_alive => 1 ) ->on_action( sub{ $_uri . "/" . $_[1] } ); my $method = SOAP::Data ->name( $methodName ) ->attr( {xmlns => $_uri . "/"} ); my $rv = $handle->call( $method=>@params ); if( $rv->fault() ){ print "SOAP Error ($methodName) :: " . $handle->transport()->status() . "\n\t" . $rv->faultcode() . ": " . $rv->faultstring(); } else { print $rv->result(); } 

Also, looking at your comment on one of the answers

codeuse SOAP :: Lite; print SOAP :: Lite → uri ('webservices.uship.com/uShipsvc.asmx?WSDL';) → proxy ('http: /webservices.uship.com') → GetCategories ('myToken') → result;

You can have uri and proxy back. Ie, the proxy should be your .asmx (without "WSDL"). If you want to use WSDL, this is a completely different connection method than using uri + proxy. See: http://guide.soaplite.com/#access%20with%20service%20description%20%28wsdl%29

+1
source

You need to fix your URIs, with http:/webservices.uship.com I get 500 No Host option provided at test-soap.pl line 7 . Change it like this:

 use SOAP::Lite; print SOAP::Lite -> uri('http://webservices.uship.com/uShipsvc.asmx?WSDL') -> proxy('http://webservices.uship.com') -> GetCategories('myToken') -> result; 
+1
source

Consider using SOAP :: Trace to track SOAP call SOAP

You can include this usage statement in your lib / script:

 use SOAP::Lite +trace => [qw/ debug method fault /]; 

This can help you debug your SOAP call.

0
source

Source: https://habr.com/ru/post/1347756/


All Articles