Soap vs Rest website services

soap-vs-rest-web-services

Web services are increasingly becoming popular these days because of their usefulness.

When it comes to truly cross software communication, only web services come in spare.

And #XML is the most common language for electronic communications.

Let us try our hands on it.
We are converting XML document to PHP array with help of web services, as follows.

namespace Application\Parse;
use SimpleXMLIterator;
use SimpleXMLElement;
$xml = simplexml_load_string($xmlstring, “SimpleXMLElement”, LIBXML_NOCDATA);
$json = json_encode($xml);
$array = json_decode($json,TRUE);
Just take care that, in XML tags, numbers alone are NOT allowed, some text should be there in front of numbers.
Otherwise it may create errors during conversion.
Similarly, reverse conversion from PHP array to XML document is also few lines of code as given below.

function to_xml(SimpleXMLElement $object, array $data)
{
foreach ($data as $key => $value) {
if (is_array($value)) {
$new_object = $object->addChild($key);
to_xml($new_object, $value);
} else {
$object->addChild($key, $value);
}
}
}
$xml = new SimpleXMLElement(‘<rootTag/>’);
to_xml($xml, $my_array)
And then, print it to verify
print $xml->asXML();

With help of web services, we can
– Create a #REST_client
– Create a #REST_server
– Create a #SOAP_client
– Create a #SOAP_server

To fix website or mobile app related complex problems, feel free to contact us at: http://www.blisswebsolution.com/web-development-and-designing-services-company.html

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s