json return using soap server and soap client using php
copy soap_server page like (index.php);
-----------------------------------------------------------------------
require_once('../lib/nusoap.php');
$server = new nusoap_server;
$server->configureWSDL('server', 'urn:server');
$server->wsdl->schemaTargetNamespace = 'urn:server';
$server->register('getrequest',
array('name' => 'xsd:string'),
array('return' => 'xsd:string'),
'urn:server',
'urn:server#getrequest');
function getrequest($value,$address)
{
$getval=array('name'=>$value,'address'=>$address);
return json_encode($getval);
}
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
------------------------------------------------------------------------------------
create soap client page (get json data form soap)getdata.php
----------------------------------------------------------------------------
require_once('../lib/nusoap.php');
$client = new soapclient('http://127.0.0.1/test/nusoap/samples/index.php?wsdl');
$res=$client->__call('getrequest',array('name'=>'bikash','address'=>'teliakan'));
if($client->fault)
{
echo "Fault: <p>Code: {$client->faultcode}<br>";
echo "String: {$client->faultstring}";
}
else
{
echo $res;
}
-----------------------------------------------------------------------
require_once('../lib/nusoap.php');
$server = new nusoap_server;
$server->configureWSDL('server', 'urn:server');
$server->wsdl->schemaTargetNamespace = 'urn:server';
$server->register('getrequest',
array('name' => 'xsd:string'),
array('return' => 'xsd:string'),
'urn:server',
'urn:server#getrequest');
function getrequest($value,$address)
{
$getval=array('name'=>$value,'address'=>$address);
return json_encode($getval);
}
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
------------------------------------------------------------------------------------
create soap client page (get json data form soap)getdata.php
----------------------------------------------------------------------------
require_once('../lib/nusoap.php');
$client = new soapclient('http://127.0.0.1/test/nusoap/samples/index.php?wsdl');
$res=$client->__call('getrequest',array('name'=>'bikash','address'=>'teliakan'));
if($client->fault)
{
echo "Fault: <p>Code: {$client->faultcode}<br>";
echo "String: {$client->faultstring}";
}
else
{
echo $res;
}
Comments
Post a Comment