Monday, September 20, 2010

building SOAP object in perl to call a web service

Follows an example perl script snippet structure to build SOAP object to call a web service

  1. Use the required library

    use SOAP::Lite +trace => 'debug';
  2. Define the SOAP object

    my $soap = SOAP::Lite
                       -> uri('http://localhost:1325/WSImpl/')
                       -> on_action( sub { return '"http://www.example.com/ws/MaterialService:updateMaterialIn"' } )
                       -> proxy('http://localhost:1325/WSImpl/MaterialService.asmx')
                       -> on_fault(sub { my($soap, $res) = @_;
                 die ref $res ? $res->faultdetail : $soap->transport->status, "\n";
               });
  3. Define the SOAP method

    my $method = SOAP::Data->name('UpdateMaterialRequest')
                ->attr({xmlns => 'http://www.example.com/ws/MaterialService'});
  4. Build the SOAP query data

    my $query = SOAP::Data->value(
        SOAP::Data->name(ServiceTags =>
        \SOAP::Data->value(
          SOAP::Data->name(UserName => ''),
          SOAP::Data->name(Pwd => ''))),
          SOAP::Data->name(Details =>
            \SOAP::Data->value(
             SOAP::Data->name(DetailsName => Name )
            )
          )
        ); 
  5. Make the Call

    $result = $soap->call($method => $query);
  6. Read the resultant data

    my $statusmes = $result->valueof('//GetResponse/Status');

No comments:

Post a Comment