Hello, I have the following web service.
<?php
function ProcessMySoapObject() {
$responce =[10];
for ($i=0; $i <10 ; $i++) {
$object = (object) ['Nombre' => 'Nombre'.$i,'Descripcion' =>'Descripcion de la'.$i,'Precio' => $i];
$responce[$i]=$object;
}
}
require_once("lib/nusoap.php");
$namespace = "http://localhost/";
$server = new soap_server();
$server->configureWSDL("Productos");
$server->wsdl->schemaTargetNamespace = $namespace;
$server->wsdl->addComplexType(
'MySoapObject',
'complexType',
'struct',
'all',
'',
array(
'Nombre' => array('name'=>'Nombre','type'=>'xsd:string'),
'Descripcion' => array('name'=>'Descripcion','type'=>'xsd:string'),
'Precio' => array('name'=>'Precio','type'=>'xsd:int'),
)
);
$server->wsdl->addComplexType(
'MySoapObjectArray',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:MySoapObject[]')),
'tns:MySoapObject'
);
$server->register(
'ProcessMySoapObject',
array(),
array('return'=>'tns:MySoapObjectArray'),
$namespace,
false,
'rpc',
false,
'Processes an array of MySoapObjects and returns one of them');
$POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';
$server->service($POST_DATA);
exit();
?>
In the function I created a for cycle simulating that it is the while that later extracted the information from the database, and generated the array of objects. All this is fine, according to everything I've researched although I'm not sure.
The array that is generated in the for is the following:
[{"Nombre":"Nombre0","Descripcion":"Descripcion de la0","Precio":0},{"Nombre":"Nombre1","Descripcion":"Descripcion de la1","Precio":1},{"Nombre":"Nombre2","Descripcion":"Descripcion de la2","Precio":2},{"Nombre":"Nombre3","Descripcion":"Descripcion de la3","Precio":3},{"Nombre":"Nombre4","Descripcion":"Descripcion de la4","Precio":4},{"Nombre":"Nombre5","Descripcion":"Descripcion de la5","Precio":5},{"Nombre":"Nombre6","Descripcion":"Descripcion de la6","Precio":6},{"Nombre":"Nombre7","Descripcion":"Descripcion de la7","Precio":7},{"Nombre":"Nombre8","Descripcion":"Descripcion de la8","Precio":8},{"Nombre":"Nombre9","Descripcion":"Descripcion de la9","Precio":9}]
Now what I want is to design the client in a C # application (form) that shows the data of the array that I am sending by means of nusoap. This is the code of the button in the C # application with which I am testing. When you add the web service reference to VisualStudio, put the name of "getProductos"
private void button2_Click(object sender, EventArgs e)
{
getProductos.Productos s = new getProductos.Productos();
getProductos.MySoapObject[] web = s.ProcessMySoapObject();
MessageBox.Show(web[5].Nombre);
MessageBox.Show(web[5].Descripcion);
MessageBox.Show(web[5].Precio.toString());
}
In this case I want to take as an example the Name, Description and Price of the object that is in position 5 of the array, however this sends me a NullReferenceExeption and an InvalidOperationExeption. They could advise me to know what I'm doing wrong or how I can get the data from my array.
Thank you in advance.