So let’s go line by line. First, we obviously include NuSOAP toolkit. For a server we need to create “soap_server” object. We don’t need debug messages, so we turn them off.
At line 15 we start to generate WSDL file. WSDL is “Web Services Description Language”, which is a XML-based language. This file basically describe web service and let us know how to use web service (access it). For a simple example we don’t need to generate WSDL file, but I’m also going to show you how you can use WSDL file to create “proxy class”. We configure target namespace and create (simple) complex type, which is our returned data. It’s a struct with two data rows, degree and forecast.
And finally we register “getWeather” method, so it can be called by a client, and we also define our complexType (WeatherData) for return value.
What follows is the actual “getWeather” function (line 32). First we check if argument is a string and return “soap_fault” if it’s not (line 53).
Our string parameter (city) is used in SQL query, where we hopefully get some data. In case of error, or if there is no data accessible, we also
return “soap_fault”. If we got some data from the database, we return it like associated array (our complexType).
What follows is the actual “getWeather” function (line 32). First we check if argument is a string and return “soap_fault” if it’s not (line 53).
Our string parameter (city) is used in SQL query, where we hopefully get some data. In case of error, or if there is no data accessible, we also
return “soap_fault”. If we got some data from the database, we return it like associated array (our complexType).
And on line 58 we pass to our service incoming data ($HTTP_RAW_POST_DATA). By the way, $HTTP_RAW_POST_DATA is only set if type of the data is unknown.
So that’s our web service, ready to be used. There are some WSDL stuffs that I also want to mention, but we will cover that at the end.
So that’s our web service, ready to be used. There are some WSDL stuffs that I also want to mention, but we will cover that at the end.