Product:
Search Type:

[Info] SOAP sample for PERL

Article ID: 2271 
Last Review: Oct,18 2007
APPLIES TO:
  • Virtuozzo for Windows 3.5.1 SP1

RESOLUTION

#!/usr/bin/perl -w
use MIME::Base64;
use Config;

my $OS=$Config;
my $HOST = 'http://192.168.0.218:8081',
   $USER = 'vzagent0',
#   $USER = 'admin',
   $PWD  = '1q2w3e',
   $URI_HEADER = 'http://www.swsoft.com/webservices/vza/WSDL/3.0.3/mailc',
   $URI_HWM    = 'http://www.swsoft.com/webservices/vza/3.0.3/hwm',
   $URI_VEM    = 'http://www.swsoft.com/webservices/vza/3.0.3/vem',
   $URI_TICKETM= 'http://www.swsoft.com/webservices/vza/3.0.3/ticketm'
   ;

my $PWD64= encode_base64( $PWD, '' );

use SOAP::Lite;

my $service = new SOAP::Lite;

print "Connect URL - [$HOST]\n User: [$USER]\n OS: [$OS]\n";

$service->proxy( $HOST );
$service->autotype( 0 );
$service->readable( 1 ); # For human readable envelopes[C
$service->transport()->timeout( 100 );
#$service->encodingspace( 'enc' );
$service->serializer()->soapversion('1.1');
if($OS eq 'linux') {
    $service->serializer()->register_ns( 'http://schemas.xmlsoap.org/soap/envelope/', 'soapenc' );
}

$SOAP::Constants::PATCH_HTTP_KEEPALIVE=1;

#$service->transport()->agent('TestAgent');
#$service->transport()->request()->header( 'Content-Type'=>'text/plain' );

#my $result = $service->login( SOAP::Data->name('user' => 'user-name' ) , SOAP::Data->name('password' =>
#                                 \SOAP::Data->value(
#                                     SOAP::Data->name('intern' => 'intern-data' )
#                                   )
#                               ) );

#my $hdr = SOAP::Header
#    ->name( 'package_header' )
#    ->attr( { 'xmlns' => 'http://www.swsoft.com/webservices/vza/WSDL/3.0.3/mailc' } )
#    ;

my $login  = SOAP::Data
    ->name( "login" )
    ->attr( {'xmlns' => $URI_TICKETM } )
    ;
   
my @loginParam =   (
#                         $hdr,
                          SOAP::Data->name('ip' =>  ) ,
                          SOAP::Data->name('user' => $USER ) ,
                          SOAP::Data->name('password' => $PWD64  )  
                   );
   
   
#my $loginParam = SOAP::Data
#               
#                  ->value(
#                         $hdr,
#                         SOAP::Data->name('user' => $USER ) ,
#                         SOAP::Data->name('password' => $PWD64  )  
#                  );
    
   
my $result = $service->call( $login => @loginParam );
if( $result->fault )
{
    print "ERROR:".$result->faultstring."\n";
    die;
}
my $ticket = $result->valueof( '//loginResponse/ticket' );
print "Ticket=";
print $ticket;
print "\n";

######################### LIST_VE ##########################
my $hdr = SOAP::Header
    ->name( 'packet_header' => \SOAP::Header->name( 'session' => $ticket  ) )
    ->attr( { 'xmlns' => $URI_HEADER } )
    ;

my $list_ve  = SOAP::Data
    ->name( "list_ve" )
    ->attr( {'xmlns' => $URI_HWM } )
    ;
   
my @list_veParam =   (
                          $hdr,
                          SOAP::Data->name('count' => 999 )
                   );

print "list_ve:";
my $ves = $service->call( $list_ve => @list_veParam );
if( $ves->fault )
{
    print "ERROR:".$result->faultstring."\n";
    die;
}
print "... [Ok]\n";

for my $i ($ves->valueof('//list_veResponse/veid'))
{
    print "veid[$i]\n";
}
######################## VE_INFO ##########################
my $ve_info  = SOAP::Data
    ->name( "ve_info" )
    ->attr( {'xmlns' => $URI_VEM } )
    ;
my @ve_infoParam =   (
                          $hdr,
                          SOAP::Data->name('status' => ),
                          SOAP::Data->name('config' =>
                           (
                              \SOAP::Data->name( 'ip' => ),
                              \SOAP::Data->name( 'base_set' => )
                           )
                         )   
                   );
print "ve_info ";
my $vi = $service->call( $ve_info => @ve_infoParam );
if( $vi->fault )
{
    print "ERROR:".$result->faultstring."\n";
    die;
}
print "... [Ok]\n";
for my $i ($vi->valueof('//ve_infoResponse/ve'))
{
    print "veid[".$i->."]"                     if $i->;
    print " status=[".$i->->. "]"     if $i->->;
    print " base_set=[".$i->->."]" if $i->->;
    print " ip=[".$i->->."]"             if $i->->;
    print "\n";
}


Please provide feedback on this article

Did this article help you solve your issue?
Yes
No
Partially
I do not know yet
 
Strongly Agree   Strongly Disagree
  9 8 7 6 5 4 3 2 1
The article is easy to understand
The article is accurate
Additional Comments:
*Please provide us with your email address in case we need to contact you.
*Please type the code you can see.
* - required fields