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

Accessing results of query against .NET webservice

Expand Messages
  • Patrick
    I am having a problem accessing the result of a query against a .NET web service. I can set outputxml() and see what is being returned (included below) however
    Message 1 of 2 , May 29, 2001
    • 0 Attachment
      I am having a problem accessing the result of a query against a .NET
      web service. I can set outputxml() and see what is being returned
      (included below) however trying to access it via $result->result
      simply returns '1'. Looking at the XML it appears to be different
      than what I see when I run it against a SOAP::Lite server.

      Anyone have any idea what I am missing?

      <---Output from outputxml()--->
      <?xml version="1.0"?>
      <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
      xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
      xmlns:xsd="http://www.w3.org/1999/XMLSchema">
      <soap:Body>
      <GetThumbnailResult xmlns="http://tempuri.org/">
      <result>

      <string>http://thumbnail.complexcode.com/ThumbnailGen/Thumbnails/63126
      7492559048256.jpeg</string>
      <string>5</string>
      <string xsi:null="true"/>
      </result>
      </GetThumbnailResult>
      </soap:Body>
      </soap:Envelope>
      <--END XML-->

      <--Code-->
      #!/usr/bin/perl
      use SOAP::Lite;
      # Since .NET doesn't appear to like charsets
      $SOAP::Constants::DO_NOT_USE_CHARSET = 1;
      my $soap = SOAP::Lite -> uri('http://tempuri.org');
      $soap->on_action(sub{join '', @_});
      $soap->proxy
      ('http://thumbnail.complexcode.com/ThumbnailGen/ThumbnailService.asmx'
      );
      #$soap->outputxml(1);
      # Create our method
      my $method = SOAP::Data->name('GetThumbnail');
      $method->attr({xmlns => 'http://tempuri.org/'});
      $url = SOAP::Data->name('url')->value("http://www.stetson.edu");
      $size = SOAP::Data->name('size')->value(250);
      my $result = $soap->call($method => $url, $size);
      if( $result->fault )
      {
      die("ERROR: A problem has occured\n");
      }
      print($result."\n");
      print($result->result."\n");
      <--END CODE-->


      Thanks.
    • Paul Kulchenko
      Hi, Patrick! server returns: http://thumbnail.complexcode.com/ThumbnailGen/Thumbnails/63126 7492559048256.jpeg 5
      Message 2 of 2 , May 29, 2001
      • 0 Attachment
        Hi, Patrick!

        server returns:

        <result>
        <string>http://thumbnail.complexcode.com/ThumbnailGen/Thumbnails/63126
        7492559048256.jpeg</string>
        <string>5</string>
        <string xsi:null="true"/>
        </result>

        which is something that will be deserialized as hash, but since all
        three elements are the same, only last one will be kept.

        > print($result."\n");
        will print SOAP::SOM object, which is '1' in this context
        > print($result->result."\n");
        will print deserialized <result>, which is HASH....

        if you try:
        print $result->result->{string}

        you'll get 'undef', since last element is not defined there (<string
        xsi:null="true"/>)

        it you want to access subelements of <result> element you can do
        something like

        foreach ($result->valueof('//string')) {
        print "$_\n";
        }

        which asks for all elements with name <string> and will return array.
        Or if you want only the first one:

        $el = $result->valueof('//string');

        or you may do

        foreach ($result->valueof('//result/[>0]')) {
        print "$_\n";
        }

        which asks for all subelements of <result> element (regardless of
        position of this element in XML message.

        You can navigate thru the message in several different ways and
        though in most cases you don't need it, sometimes (like in this case)
        it might be handy. Let me know if you still have any problems with
        that.

        Best wishes, Paul.

        P.S. you can use $soap->on_debug(sub{print@_}) instead of outputxml()

        --- Patrick <codemonky@...> wrote:
        > I am having a problem accessing the result of a query against a
        > .NET
        > web service. I can set outputxml() and see what is being returned
        > (included below) however trying to access it via $result->result
        > simply returns '1'. Looking at the XML it appears to be different
        > than what I see when I run it against a SOAP::Lite server.
        >
        > Anyone have any idea what I am missing?
        >
        > <---Output from outputxml()--->
        > <?xml version="1.0"?>
        > <soap:Envelope
        > xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
        > xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
        > xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
        > xmlns:xsd="http://www.w3.org/1999/XMLSchema">
        > <soap:Body>
        > <GetThumbnailResult xmlns="http://tempuri.org/">
        > <result>
        >
        >
        <string>http://thumbnail.complexcode.com/ThumbnailGen/Thumbnails/63126
        > 7492559048256.jpeg</string>
        > <string>5</string>
        > <string xsi:null="true"/>
        > </result>
        > </GetThumbnailResult>
        > </soap:Body>
        > </soap:Envelope>
        > <--END XML-->
        >
        > <--Code-->
        > #!/usr/bin/perl
        > use SOAP::Lite;
        > # Since .NET doesn't appear to like charsets
        > $SOAP::Constants::DO_NOT_USE_CHARSET = 1;
        > my $soap = SOAP::Lite -> uri('http://tempuri.org');
        > $soap->on_action(sub{join '', @_});
        > $soap->proxy
        >
        ('http://thumbnail.complexcode.com/ThumbnailGen/ThumbnailService.asmx'
        > );
        > #$soap->outputxml(1);
        > # Create our method
        > my $method = SOAP::Data->name('GetThumbnail');
        > $method->attr({xmlns => 'http://tempuri.org/'});
        > $url = SOAP::Data->name('url')->value("http://www.stetson.edu");
        > $size = SOAP::Data->name('size')->value(250);
        > my $result = $soap->call($method => $url, $size);
        > if( $result->fault )
        > {
        > die("ERROR: A problem has occured\n");
        > }
        > print($result."\n");
        > print($result->result."\n");
        > <--END CODE-->
        >
        >
        > Thanks.
        >
        >
        > To unsubscribe from this group, send an email to:
        > soaplite-unsubscribe@yahoogroups.com
        >
        >
        >
        > Your use of Yahoo! Groups is subject to
        > http://docs.yahoo.com/info/terms/
        >
        >


        __________________________________________________
        Do You Yahoo!?
        Yahoo! Auctions - buy the things you want at great prices
        http://auctions.yahoo.com/
      Your message has been successfully submitted and would be delivered to recipients shortly.