DevZone
DevZone

Reputation: 63

Perl module not getting correct web service output

Can someone validate this snippet and point out what I might be doing wrong?

This is my code which creates and does a SOAP call.

my $soap = SOAP::Lite->new()->proxy($proxy)->ns('http://example.com', 'ser')->getInfo(
  SOAP::Data->name(chronicId    => $ticket_num)->prefix('ser'),
  SOAP::Data->name(sourceSystem => $sourceSystem)->prefix('ser'),
  SOAP::Data->name(outputFormat => $outputFormat)->prefix('ser'),
  SOAP::Data->name(uid          => $uid)->prefix('ser'),
  SOAP::Data->name(username     => $username)->prefix('ser'),
  SOAP::Data->name(guid         => $guid)->prefix('ser')
);

$results = $soap->call($method);

This is the result I get, when I use a test script to execute the above code.

<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
    <ns:getChronicInfoResponse xmlns:ns="http://example.com">
      <ns:return xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">
        {
          "UID":"abc1234",
          "GUID":"",
          "CHRONICID":123,
          "OUTPUTFORMAT":"json",
          "USERNAME":"xyz",
          "STATUS_SUB_CODE_NAME":"Active",
          "SOURCESYSTEM":"abc",
          "STATUS_NAME":"Open"
        }
      </ns:return>
    </ns:getChronicInfoResponse>
  </soapenv:Body>
</soapenv:Envelope>

However when I try to read the web server response into a variable and print it out, all I get is a 1 (it's not empty though) nothing else. The output is supposed to be in JSON, as shown above, which I would then need to parse.

Any guesses what I might be doing wrong? I am new to Perl so it could be a silly thing.

Upvotes: 0

Views: 83

Answers (1)

DevZone
DevZone

Reputation: 63

Sorry I missed the updates. I could use the dumper to see a proper response here, seems like I was receiving a hex value while doing a print on the results which was not right.

The dumper returns a JSON string like -

{
          'return' => '{"ATTUID":"pm304a","GUID":"d353f542-43f6-421b-9573-4c9c39ce77e3","CHRONICID":420,"OUTPUTFORMAT":"json","USERNAME":"m91619","STATUS_SUB_CODE_NAME":"Active","SOURCESYSTEM":"Oasis","STATUS_NAME":"Open"}'
        };

Now I am trying to parse this json using JSON:XS - decode_json, but end up in an error which says

Malformed JSON string neither array, object, number, string or atom,......

I think thats because of the 'return' in the string, maybe I can strip it out and then pass to decode?

Upvotes: 1

Related Questions