I developed a web service using nusoap, seems that the web service works fine, in fact is very simple, I put here the code:
<?php
// Pull in the NuSOAP
require_once('lib/nusoap.php');
// Create the server instance
$server = new soap_server();
// Initialize WSDL support
//(MyService is name of our service)
$server->configureWSDL('WebService', 'urn:WebService');
// Character encoding
$server->soap_defencoding = 'utf-8';
//Register Insert user function
$server->register(
'InsertData', //Name of function
array('Id' => 'xsd:int',
'userName' => 'xsd:string',
'Pass' => 'xsd:string',
'Mail' => 'xsd:string'), //Insert Values
array('return' =>'xsd:boolean'), //return Values
'urn:ServiceWsdl', //Namespace
'urn:ServiceWsdl#InsertData', //SoapAction
'rpc', //style
'literal', //can be encoded but it doesn't work with silverlight
'Insert function to register users'
);
//Register GetData function
$server->register(
'GetData',
array('Id' => 'xsd:int'),
array('Id' => 'xsd:int',
'userName' => 'xsd:string',
'Pass' => 'xsd:string',
'Mail' => 'xsd:string'), //return values
'urn:ServiceWsdl',
'urn:ServiceWsdl#GetData',
'rpc',
'literal',
'Get all users function'
);
function InsertData($id, $userName, $Pass, $Mail) {
$connect = mysql_connect("server","userDB","passDB");
if ($connect) {
if(mysql_select_db("database", $connect)) {
mysql_query( "INSERT INTO `Users`(`Id`, `UserName`, `Pass`, `Mail`) VALUES (`".$id."`,`".$userName."`,`".$Pass."´,`".$Mail."`);");
return true;
}
}
return false;
}
function GetData($Id) {
$connect = mysql_connect("server","userDB","passDB");
if ($connect) {
if(mysql_select_db("database", $connect)) {
$sql = "SELECT * FROM Users";
$result = mysql_fetch_array(mysql_query($sql));
return $result['Id']."-".$result['UserName']."-".$result['Pass']."-".$result['Mail'];
}
}
return false;
}
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
And my code on the Android Xamarin project (working from Visual Studio 2013) is very simple too:
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
// Get our button from the layout resource,
// and attach an event to it
Button button = (Button) FindViewById<Button>(Resource.Id.MyButton);
TextView labelText = (TextView)FindViewById<TextView>(Resource.Id.editTextUserName);
button.Click += delegate
{
//showMessageWithName(labelText.Text);
AvitecWS service = new AvitecWS();
if (service.InsertData(69, "AnUser", "anUserPassword", "anUser@mail.com"))
{
//the following method just show a message :)
showMessageWithName("Message has been send!");
}
else
{
showMessageWithName("Upss... something was wrong :(");
}
};
}
Then, when I click the button and the app should to do the insert I 've got the following exception:
I think that it is happening because the format of the SOAP object is not correct, but I can't view where is error :(
I REALLY appreciate any help.
Thanks in advance.