Wednesday, September 09, 2015

What is the difference between SOAP and POX on Web Services

My previous two blog talks about two aspects of Web Services. What is the differences between the two methods. To make it simple, it is basically the same except that one is easier and the other is harder. They both return exactly the same result.

Let's talk about the easier one. Using SOAP is by far the easiest way. You just need to compose an array according to the documentation available for the Web Services and send to a function of the WS object.

The harder one is to compose the XML envelop then add the nodes to make a complete XML document and then send it.

How did the Web Services work with two different methods? Actually they are both the same except that the XML is posted to the second stage. Allow me to explain the process.

When we use SOAP, we creates a connection to the Web Services (henceforth WS). We then called the particular function via the connection object and pass it an array of parameters. In PHP the script is as follows.

$client= new SoapClient("http://webservices_address", $opt);
$param=array('action'=>'theaction');
$test=$client->thefunction($param);
echo $test->functionresponse->result;

Now if the arguments is a multiple array type the $param will be something like this

$param=array('action'=>array('subaction'=>subtheaction'))

You have to know what function to call and what parameter to pass. Normally this is found in WS documentations. Now, it is very important to be specific about the object name of the array. It is often case sensitive. "subaction" is not the same as "subAction". Often WS will simply tells you that a parameter is missing because of case differences.

To a user, the PHP script is all that is needed to get it working. In actual fact PHP works in the back ground and actually posts the data in a different form. You guess it right. It actually posts a XML to WS after composing it from the WSDL that it first addressed to. This means that it actually interprets the returned value when it first posts to WS, compose the XML based on the definition then sends the XML to another address (usually a sub address of the original) according to the definition.

Our second method actually composes the XML directly and posts to the sub address. It is therefore the same thing except you need to compose the XML the hard way unless you download the WSDL of the WS and do a transpose yourself.

How does the multiple array looks in XML? It is exactly the same except in different format.

subtheaction

Obviously, the PHP array is much easier to read. Now, you would say why not just use SOAP since it is much easier? Yes it is unless the application you use does not have SOAP functionality. PHP have both SOAP and CURL (which provide POX functionality by sending the XML as post). If I use PHP I would prefer to use SOAP instead of CURL. What if you use an application for your business but that application only have CURL?

Since CURL can post a XML to the WS and still gets back the same result, it is pretty alright to use it to access WS. It will be more difficult as you will need to understand what to do when composing the entire XML. Some WS does provide the XML information and allows POX.

Filemaker is a good application for a small business. It is very easy to create a complete database application without much technical knowledge. To access to WS, there is no choice but to use CURL. It might be harder but it will still work.

Actually Filemaker can post to a web site and gets the result but then it has to call a PHP script, pass the information to it and it in turn calls WS, get the result and return it to Filemaker. It is pretty round the world way but it still works.

Post note. SOAP communication has been discontinued. The only way is to use POX now.




No comments:

Post a Comment