1

I want to send data as xml from client to server using nusoap in php webservice. I am able to send it as an array. this is my code.

Client

 <?php
$name='admin';
$pass='admin';
if(isset($_POST['submit'])){
require_once('lib/nusoap.php');
$client = new nusoap_client('http://localhost/web_service/server.php?wsdl', true);
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
  }
  $result = $client->call('login', array('name' => $name,'pass'=>$pass));
 if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
  } else {
$err = $client->getError();
if ($err) {
    echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
    echo '<h2>Result</h2><pre>';
    print_r($result);
echo '</pre>';
}
   }
   }
   ?>

Server

 <?php
require_once('lib/nusoap.php');
$server = new soap_server();
$server->configureWSDL('server', 'urn:server');
$server->register('login',
array('name' => 'xsd:string','pass'=>'xsd:string'),     
array('return' => 'xsd:string'),    
'urn:server',                   
'urn:server#login',             
'rpc',                              
'encoded',                          
'Login Authentication'
    );

    function login($name,$pass) {
   if($name && $pass == 'admin'){
   return 'Welcome, ' . $name;
   }
   else{
   return '<h2>Oops,</h2> looks like something went wrong. Please try again';
    }
      }
  $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
    $server->service($HTTP_RAW_POST_DATA);
     ?>

I am looking to send the variables $name & $pass to server as xml and need the server to parse the xml and get the values. Is this possible.

Alessandro Minoccheri
  • 35,521
  • 22
  • 122
  • 171
Developer
  • 1,030
  • 6
  • 14
  • 37
  • It is possible - just make the server side send XML, and the client side parse the XML. Do you have a specific question? – Pekka Nov 05 '12 at 09:49
  • @Pekka: Thanks for your reply. Could you provide an eg:. – Developer Nov 05 '12 at 09:55
  • for generating XML: [how to generate xml file dynamically using PHP?](http://stackoverflow.com/q/486757) for parsing use e.g. SimpleXML: http://php.net/manual/en/book.simplexml.php – Pekka Nov 05 '12 at 09:57
  • @Pekka: How can i send it to server and how to parse it in server side. – Developer Nov 05 '12 at 10:02

0 Answers0