How to make PHP Web Service with NuSoap

While investigating how to create a Web Service in PHP I run into NuSoap library, that can generate WSDL based on some matadata describing Web Service method signatures and the data structures. I downloaded NuSoap library and found some trivial sample that started working after adding the highlighted line of code:

function ProcessSimpleType($who) {
    return "Hello $who";
}

require_once("lib/nusoap.php");
$namespace = "http://sometest.com/vms2";
// create a new soap server
$server = new soap_server();
$server->soap_defencoding = 'UTF-8'; 
// configure our WSDL
$server->configureWSDL("SimpleService");
// set our namespace
$server->wsdl->schemaTargetNamespace = $namespace;
// register our WebMethod
$server->register(
                // method name:
                'ProcessSimpleType',          
                // parameter list:
                array('name'=>'xsd:string'), 
                // return value(s):
                array('return'=>'xsd:string'),
                // namespace:
                $namespace,
                // soapaction: (use default)
                false,
                // style: rpc or document
                'rpc',
                // use: encoded or literal
                'encoded',
                // description: documentation for the method
                'A simple Hello World web method');
                
// Get our posted data if the service is being consumed
// otherwise leave this data blank.                
$POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA']) 
                ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';

// pass our posted data (or nothing) to the soap service                    
$server->service($POST_DATA);                
exit();

C# client that uses the Web Service wrapper generated by MS Visual Studio 2010 consists of three lines:

ServiceReference1.SimpleServicePortTypeClient client = new ServiceReference1.SimpleServicePortTypeClient();

string s = client.ProcessSimpleType("steve");

Console.WriteLine(s);

1 Response to How to make PHP Web Service with NuSoap

  1. Esther says:

    I was using godaddy dedicated server and that time all my services were working fine. Recently moved to shared hosting server. Now the service which doesn;t have input param is not returning results. So i made change to have input param in that service however in device side that service will be non-input and not returning results. How to achieve in server side or is it possible to set default value. Please help me.

Leave a Reply

Your email address will not be published. Required fields are marked *