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.