Building XML Web Services with PHP NuSOAP - Walkthrough Example 1
(Page 3 of 5 )
The installation of NuSOAP is a straightforward process.
Download the files and extract the file nusoap.php from the zip. For easy access, copy the classes to a location in your include path, or into the directory (say, http://yourServer.com/nusoap/) in which you will be using the classes. Let’s develop a simple SOAP server with NuSOAP toolkit that will provide update information (whether a new update is released) of your software product, which is installed in the customer’s computers.
Listing: cvs.php Create a file (in this example, cvs.php) and copy it to location http://yourServer.com/nusoap/
<?php
require_once('nusoap.php'); // include the NuSOAP classes
$s = new soap_server; // instantiate the server object, provided by soap_server classes
$s->register('cvs'); /* to allow our function to be called remotely, we must register it with the server object. If this is not done server will generate a fault indicating that the service is not available if a client accesses the service. In the absence of such a registration process, any PHP functions would be remotely available, which would present a serious security risk. */
function cvs ($StrBuild){ /* Now define our simple function that we are exposing as service. Notice that we first check to make sure a string (version info) was passed. If the parameter is not a string, we use the soap_fault class to return an error to the client. */
// Optionally catch an error and return a fault
if($StrBuild == ''){
return new soap_fault('Client','','Must supply a valid build string.');
}
if ($StrBuild < "200212") { // If customer is using an older version of the product
return "A new version of this product is available now for download, please visit http://www.wordware.com/education";
}
if ($StrBuild =="200212") {
return "Update Not Necessary. Thank you for using our product.";
}
}
$s->service($HTTP_RAW_POST_DATA); /* The final step is to pass any incoming posted data to the SOAP server’s service method. The method processes the incoming request and calls the appropriate function (in our case cvs ()). It will then formulate the response. */ Now how your product will use this service, which will automatically notify your customer if a new version of your application is available. For simplicity sake we will design the following dialog with VB. You can download the project file. You will find enough commentary with code, which describes how to build SOAP envelope and parsing XML document with Microsoft XML parser.
Figure 2.1
Figure 2.2Next: Walkthrough Example 2 >>
More PHP Articles
More By Ahm Asaduzzaman