Web Service response handling

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tsetse
Forum Newbie
Posts: 3
Joined: Sat Apr 27, 2013 1:52 am

Web Service response handling

Post by tsetse »

Hello ppl,

Can pls anyone help on the following problem?

I am writting an application that consumes several web services, using SoapClient or cURL client.

The problem is that the response of one of these services is really weird... From the server-side specs the response should be a defined object. From my client side of view, the response is a string of an xml.

In my code :
$client = SoapClient(...);
$result = $client->myMethod();
OR
$result = curl_exec(...)

Result :
- when I use: "echo $result", the output is a string with only tag values displayed sequentially
- when I use: "var_dump($result)", the result is an empty object!
- when I use: "echo htmlentities($result)", the output is the xml response
- I have also tried to convert this string (of xml) to an array, using SimpleXML, but it resulted in an empty array...

My question is how such a response can be handled! I want to be able to retrieve specific values by i.e. $result->item, and not by parsing the string (even this is not easily possible since the tags in a string have strange behaviour)

Can someone give any idea?

Thanks a lot :)
User avatar
mecha_godzilla
Forum Contributor
Posts: 375
Joined: Wed Apr 14, 2010 4:45 pm
Location: UK

Re: Web Service response handling

Post by mecha_godzilla »

Hi,

To avoid complicating things, I suggest you start with cURL and then use the in-built PHP functions to parse your XML into an array:

http://uk.php.net/manual/en/book.xml.php

If you can see the XML data that you're expecting then this confirms that your cURL script is working correctly. If you need any further assistance working with cURL, post your code here so that forum members can see whether it is correct or not.

If you want an OOP implementation instead, it would be a good idea to give more details about what it is that you're trying to achieve - how will the data be used, and what benefits will using an OOP interface give you that an array interface will not.

HTH,

Mecha Godzilla
Post Reply