Loading ...
Sorry, an error occurred while loading the content.

I can't see fault codes

Expand Messages
  • William Denton
    Hi, I m using SOAP::Lite to talk to a Windows box running .NET that gives me a number if I call a createMSA routine and give it an address. I can t seem to
    Message 1 of 2 , Jun 20, 2002
    • 0 Attachment
      Hi,

      I'm using SOAP::Lite to talk to a Windows box running .NET that gives me a
      number if I call a "createMSA" routine and give it an address. I can't
      seem to get at the fault codes with $thing->fault, however. I do this:

      use SOAP::Lite
      SOAP::Data->import('name');
      my $soap = SOAP::Lite
      -> service('http://dotnet/box/msa.asmx?WSDL') # The WSDL works fine
      -> on_fault(\&soap_error);

      my $msa = $soap -> createMSA
      (SOAP::Data ->type('string') ->name(age => '3'),
      SOAP::Data ->type('string') ->name(name => 'Throckmorton'),
      );

      print "* MSA = $msa\n"; # A number, if all went well

      unless ($msa->fault) {
      print "* msa->result = ", $msa->result(), "\n";
      } else {
      print "* Fault! ", join ', ',
      $msa->faultcode, $msa->faultstring, $msa->faultdetail;
      }

      sub soap_error {
      my ($soapObj, $res) = @_;
      if (ref $res) {
      print "(" . $res->faultcode . ") " . $res->faultstring .
      " (" . $res->faultdetail . ")\n";
      } else {
      print $soapObj->transport->status, "\n";
      }
      # exit 0; # Unused so it'll keep running
      }


      That "unless ($msa->fault)" line gives me this error when there's a fault:

      Can't call method "fault" without a package or object reference

      I coped that out of some docs, and I can't see why it doesn't work. If I
      catch faults with a subroutine, like soap_error, then I can see the
      faultcode and faultstring just fine. I'd like to see them in the main
      flow of the program, though. Am I not understanding something about the
      nature of the object? Any help most appreciated.

      Bill
      --
      William Denton : Toronto, Canada : http://www.miskatonic.org/ : Caveat lector.
    • Duncan Cameron
      ... This seems to be tripping-up a few people recently. When using the service() approach, the result of your createMSA is not a SOM object, it really is the
      Message 2 of 2 , Jun 20, 2002
      • 0 Attachment
        On 2002-06-20 William Denton wrote:
        >Hi,
        >
        >I'm using SOAP::Lite to talk to a Windows box running .NET that gives me a
        >number if I call a "createMSA" routine and give it an address. I can't
        >seem to get at the fault codes with $thing->fault, however. I do this:
        >
        > use SOAP::Lite
        > SOAP::Data->import('name');
        > my $soap = SOAP::Lite
        > -> service('http://dotnet/box/msa.asmx?WSDL') # The WSDL works fine
        > -> on_fault(\&soap_error);
        >
        > my $msa = $soap -> createMSA
        > (SOAP::Data ->type('string') ->name(age => '3'),
        > SOAP::Data ->type('string') ->name(name => 'Throckmorton'),
        > );
        >
        > print "* MSA = $msa\n"; # A number, if all went well
        >
        > unless ($msa->fault) {
        > print "* msa->result = ", $msa->result(), "\n";
        > } else {
        > print "* Fault! ", join ', ',
        > $msa->faultcode, $msa->faultstring, $msa->faultdetail;
        > }
        >
        > sub soap_error {
        > my ($soapObj, $res) = @_;
        > if (ref $res) {
        > print "(" . $res->faultcode . ") " . $res->faultstring .
        > " (" . $res->faultdetail . ")\n";
        > } else {
        > print $soapObj->transport->status, "\n";
        > }
        > # exit 0; # Unused so it'll keep running
        > }
        >
        >
        >That "unless ($msa->fault)" line gives me this error when there's a fault:
        >
        > Can't call method "fault" without a package or object reference
        >
        >I coped that out of some docs, and I can't see why it doesn't work. If I
        >catch faults with a subroutine, like soap_error, then I can see the
        >faultcode and faultstring just fine. I'd like to see them in the main
        >flow of the program, though. Am I not understanding something about the
        >nature of the object? Any help most appreciated.
        >
        This seems to be tripping-up a few people recently. When using the
        service() approach, the result of your createMSA is not a SOM object,
        it really is the result of your call. So you can't call the fault()
        method on it, nor the result() method either.

        To get the flexibility you want you need to specify the proxy and uri
        directly. The result of your createMSA call will then be a SOM object.

        my $s = SOAP::Lite
        ->proxy(...)
        ->uri(...)
        ;

        my $r = $s->createMSA();

        unless ($r->fault) {
        print $r->result

        etc.

        Regards,
        Duncan Cameron
      Your message has been successfully submitted and would be delivered to recipients shortly.