I am building a nusoap api for my vb.net application to consume - currently I am trying to send many rows of mysql data to my client so I built this.
When I try to consume it in Vb.net I am getting the classic:
...msdiscocodegenerator failed unable to import binding... Unable to import binding... from namespace
Further info: error states:
Custom tool error: Unable to import WebService/Schema. Unable to import binding 'Testing_ServiceBinding' from namespace 'urn:Testing_Service'. Unable to import operation 'GetData'. The datatype 'urn:Testing_Service:return_array_php' is missing.
Obviously I have an error in my code somewhere that VS doesn't like. WSDL inspectors are all saying good apart from some camel-casing
Why am I getting that error
require_once('lib/nusoap.php'); // basic include.. must go at the top
$SERVICE_NAMESPACE = "urn:Testing_Service"; // create a namespace to run under.
$server = new soap_server(); // the soap object from the include above.
// this has many input parameters but we only need two: the service name and the namespace
$server->configureWSDL('Testing_Service', $SERVICE_NAMESPACE);
////////////////////////
// //
// Mysql Test //
// //
////////////////////////
$server->wsdl->addComplexType(
'dataArray', // MySoapObjectArray
'complexType', 'array', '', 'SOAP-ENC:Array',
array(),
array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:return_array_php[]')), 'tns:return_array_php'
);
$server->register(
'GetData',
array(),
array('return'=>'tns:dataArray'),
$namespace,
false,
'rpc',
'encoded',
'mysql test data'
);
function GetData()
{
$servername = "localhost";
$username = "user";
$password = "password";
try {
$conn = new PDO("mysql:host=$servername;dbname=EMRFTD", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// echo "Connected successfully";
}
catch(PDOException $e)
{
// echo "Connection failed: " . $e->getMessage();
}
//already connected to pdo
// select statement.
$sql = $conn->prepare("SELECT c.RID AS RID, c.Utype AS Utype, c.Curgency as Curgency, firstname, lastname, putime, slocname, slocadd, sloccity, slocstate, Scene, Dest, dlocname, dlocadd, dloccity, dlocstate, s.fid AS sfid, s.name AS sname, s.faddress AS sfaddress, s.fcity AS sfcity, s.fstate AS sfstate, s.fcontnumb AS sfcontnumb, s.fcontname AS sfcontname, s.fcontract AS sfcontract, d.fid AS dfid, d.name AS dname, d.faddress AS dfaddress, d.fcity AS dfcity, d.fstate AS dfstate, d.fcontnumb AS dfcontnumb, d.fcontname AS dfcontname, d.fcontract AS dfcontract FROM calls c LEFT JOIN patients p ON c.Pnumb = p.pid LEFT JOIN facilities s ON c.Scene = s.fid LEFT JOIN facilities d ON c.Dest = d.fid WHERE 1 ORDER BY :orderby asc");
$sql->execute(array(':orderby' => "putime")); //leaving this so we can change the order programatically later
$results = $sql->fetchAll();
$counts = 0;
if ( count($results) ) {
foreach($results as $row) {
$result[$counts] = array(
"RID" => $row['RID'],
"Utype" => $row['Utype'],
"Curgency" => $row['Curgency']
);
$counts = $counts+1;
}
} else {
$result = null;
}
return $result;
}
//process request.
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
The entire mysql transaction works great including placing the data into an array - doing a vardump shows:
array(2) { [0]=> array(3) { ["RID"]=> string(4) "4117" ["Utype"]=> string(13) "ALS Ambulance" ["Curgency"]=> string(1) "1" } [1]=> array(3) { ["RID"]=> string(4) "4118" ["Utype"]=> string(13) "BLS Ambulance" ["Curgency"]=> string(1) "1" } }
Why wont VS consume this?
I found the error I am encountering is from a lack of array definition - I changed the complex type statements to include both definitions:
$server->wsdl->addComplexType(
'DataArr', // the type's name
'complexType', // yes.. indeed it is a complex type.
'struct', // php it's a structure. (only other option is array)
'all', // compositor..
'',// no restriction
array(
'RID' => array('name'=>'RID','type'=>'xsd:string'),
'Utype' => array('name'=>'Utype','type'=>'xsd:string'),
'Curgency' => array('name'=>'Curgency','type'=>'xsd:string')
)// the elements of the structure.
);
// Here we need to make another complex type of our last complex type.. but now an array!
$server->wsdl->addComplexType(
'dataArray',//glorious name
'complexType',// not a simpletype for sure!
'array',// oh we are an array now!
'',// bah. blank
'SOAP-ENC:Array',
array(),// our element is an array.
array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:DataArr[]')),//the attributes of our array.
'tns:DataArr'// what type of array is this? Oh it's an array of mytable data
);
Hope this helps someone else in the future who encounters similar errors