c# - how to consume php webservice which return multidimensional array in .net -
i have created 1 web service in php returns me data in multidimensional array, problem how consume in .net. know consume web service return data in 1 dimensional arrays don't know multidimensional array, have included code below please me
server side php file
<?php require_once('lib/nusoap.php'); $server = new soap_server(); $server->configurewsdl('servcarrent', 'urn:servcarrent'); $server->wsdl->addcomplextype('getallkeydata','complextype','array','all','', array( 'keyid'=> array('name'=>'keyid', 'type' =>'xsd:int'), 'keyname'=> array('name'=>'keyname', 'type' =>'xsd:string'), 'isavailable'=> array('name'=>'isavailable', 'type' =>'xsd:int'), 'noofkeys'=> array('name'=>'noofkeys', 'type' =>'xsd:int') ) ); $server->wsdl->addcomplextype( 'mysoapobjectarray', 'complextype', 'array', '', 'soap-enc:array', array(), array(array('ref'=>'soap-enc:arraytype','wsdl:arraytype'=>'tns:getallkeydata[]')), 'tns:getallkeydata' ); $server->register( 'getallkeys', array(), array('return'=>'tns:mysoapobjectarray'), $ns, false, 'rpc', false, 'processes array of mysoapobjects , returns 1 of them'); function getallkeys() { $con=mysql_connect('localhost','root','pass')or die("cannot connect"); mysql_select_db('mydb')or die("cannot select db"); $sql = 'select * keytable'; $result=mysql_query($sql,$con); $out=array(); while($row = mysql_fetch_assoc($result)) { $out[]=$row; } return $out; } $http_raw_post_data = isset($http_raw_post_data) ? $http_raw_post_data : ''; $server->service($http_raw_post_data); exit(); ?>
client side php file
<?php require_once('lib/nusoap.php'); $client = new nusoap_client('http://www.mydomainname.com/new/servcarrent.php?wsdl'); $err = $client->geterror(); if ($err) { echo '<h2>constructor error</h2><pre>' . $err . '</pre>'; } $response = $client->call('getallkeys'); if($client->fault) { echo '<h2>fault</h2><pre>'; echo '</pre>'; } else { $err = $client->geterror(); if ($err) { echo '<h2>error</h2><pre>' . $err . '</pre>'; } else { echo '<h2>result</h2><pre>'; print_r($response); echo '</pre>'; } } ?>
if run client side file can access data, shown below
result array ( [0] => array ( [0] => 1 [1] => 20577369y [2] => 1 [3] => 2 ) [1] => array ( [0] => 2 [1] => 63337921s [2] => 1 [3] => 2 ) )
but want access in .net, have included web reference in .net project , named websercarrent , have tried follows giving me error in xml document
websercarrent.servcarrent scr = new websercarrent.servcarrent(); websercarrent.getallkeydata[] gakd = new websercarrent.getallkeydata[10]; gakd = scr.getallkeys(); (int = 0; < gakd.length; i++) { string kname = gakd[i].keyname; }
please me
friends got solution , working fine. made changes in server side php file replaced
$server->wsdl->addcomplextype('getallkeydata','complextype','array','all','', array( 'keyid'=> array('name'=>'keyid', 'type' =>'xsd:int'), 'keyname'=> array('name'=>'keyname', 'type' =>'xsd:string'), 'isavailable'=> array('name'=>'isavailable', 'type' =>'xsd:int'), 'noofkeys'=> array('name'=>'noofkeys', 'type' =>'xsd:int') ) );
with
$server->wsdl->addcomplextype('getallkeydata','complextype','struct','all','', array( 'keyid'=> array('name'=>'keyid', 'type' =>'xsd:int'), 'keyname'=> array('name'=>'keyname', 'type' =>'xsd:string'), 'isavailable'=> array('name'=>'isavailable', 'type' =>'xsd:int'), 'noofkeys'=> array('name'=>'noofkeys', 'type' =>'xsd:int') ) );
and while accessing in .net file there error, error free code in .net file follows
websercarrent.servcarrent scr = new websercarrent.servcarrent(); websercarrent.getallkeydata[] gakd = new websercarrent.getallkeydata[10]; (int = 0; < gakd.length; i++) { gakd[i] = scr.getallkeys()[i]; int id = gakd[i].keyid; string kname = gakd[i].keyname; }
and working ... :)
Comments
Post a Comment