webservice nusoap in php Reviewed by Momizat on . Server Side Code (server.php) [php] <?php require_once('nusoap.php'); // Create the server instance $ns="http://phpshortnotes.com"; // create SOAP Server Side Code (server.php) [php] <?php require_once('nusoap.php'); // Create the server instance $ns="http://phpshortnotes.com"; // create SOAP Rating: 0

webservice nusoap in php

Server Side Code (server.php)

<?php
require_once('nusoap.php');

// Create the server instance
$ns="http://phpshortnotes.com";
// create SOAP server object
$server = new soap_server();
// setup WSDL file, a WSDL file can contain multiple services
$server->configureWSDL('API',$ns);
$server->wsdl->schemaTargetNamespace=$ns;
$server->wsdl->addComplexType(
 'ListArray',
 'complexType',
 'array',
 '',
 'SOAP-ENC:Array',
  array(),
  array(
    array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'xsd:string[]')
  ),
  'xsd:string'
);

//for array list response
$server -> register('getData1', array('user' => 'xsd:int', 'pass' => 'xsd:int'),array('response' => 'tns:ListArray'),
    'http://soapinterop.org/');

// for string response
$server -> register('getData', array('user' => 'xsd:int', 'pass' => 'xsd:int'),array('response' => 'xsd:string'),
    'http://soapinterop.org/');

 function getData ($u,$p)
 {
   $items = $u.'#'.$p;
   return $items;
}
function getData1 ($u,$p)
 {
   $items = array($u,$p);
   return $items;
}


// Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>

Client side code

<?php
require_once('nusoap.php');
$wsdl="http://phpshortnotes.com/server.php?wsdl";
$client=new nusoap_client($wsdl, 'wsdl');

$client = new nusoap_client($wsdl);
//parameter of function
$param = array('user' => 'manish', 'pass' => 'man');
//function calling
$returnval = $client->call("getData1",$param);
//error from server side
$err = $client->getError();
if($err){
	echo "<strong>Error:</strong>".$err;
}

if($client->fault)
{
	echo "Error".$client->error_str;
}
else
{
	//Response from server
	print_r($returnval);
}

?>

Soap Client

$client     = new SoapClient('http://phpshortnotes.com/test.php?wsdl', array("trace" => 1, "exception" => 0));
$Functions = $client->__getFunctions();
//print_r($Functions);

$Types = $client->__getTypes();
//print_r($Types);



$param = array('user' => 'manish', 'pass' => 'man');
$result = $client->getData1('manish','man');
//$result = $client->getData(5,10);
print_r($result);

$LastRequest = $client->__getLastRequest();
print_r($LastRequest);

Leave a Comment

© 2014 Powered By