This post will show a simple example of how to interpret a WSDL file and a very simple, yet quick example of how to extract information from this file through PHP. Before this post try in your host please check the php info to see your host soap is enable or not.






Code Structure:


Work example:

WSDL file: For the example WSDL file we'll take this WSDL file. It's about the World Championship football.

Let's try and print the top goal scorers of the tournament. For doing this, we can see the following on line 1116-1120 as like


We now see that the operation we should call is called TopGoalScorers. This operation expects as input a TopGoalScorersSoapRequest. We don't know what it is yet, so let's find out. If we search the document for this message, we get to line 868-870 as like


Right. So now we know that the TopGoalScorersSoapRequest consists of just one part (the parameters). We know that the element is called TopGoalScorers, but we do not know anything about this parameter yet. So we search the document for the element TopGoalScorers. We can find this element at line 360-366 as like

Now there we have it: we now finally know that the method TopGoalScorers which we saw in the first WSDL fragment expects one parameter as input. This parameter is called iTopN and is of the type int.




Getting to the code:
Finally we can do something with the WSDL. Actually we can do this in a very short way thanks to the PHP SoapClient!

Calling the service with the parameter and obtaining the results can be done in just 2 lines of code. Let's give it a try and obtain the top 5 goal scorers. We can do this by the following two lines:

1.    $client = new SoapClient("http://footballpool.dataaccess.eu/data/info.wso?wsdl");
2.    $result = $client->TopGoalScorers(array('iTopN'=>5));

Note that we use the information we obtained from the WSDL file here: on the $client object, we call the method TopGoalScorers and provide an array of parameters. In this case the array contains only one parameter: the iTopN parameter with an int value of 5. The result will contain an object, so you will need to traverse the object structure.


Complete Code:


To know about how to make api go to here.