I have been using perl and mySql for just over a day and have written a basic web service PHP client/server that queries a database and returns the results to the client. I have some experience using java web services and JAX-WS.
Due to the lack of typing the handling of complex types is quite different than in JAX-WS in that no type validation is done on the return or input parameter. The server returns a multi dimensional array to the client and all works correctly.
While playing around with the WSDL I noticed that the type declarations have no affect, despite being referenced in the part element of the message element. I deleted the entire types declaration and the program continued to work correctly.
Am I missing something, is there anyway in PHP to use the WSDL to enforce the web service contract?
------- client ---------
<?php
// turn off the WSDL cache
ini_set("soap.wsdl_cache_enabled", "0");
$client = new SoapClient("http://localhost/~someuser/apams/apams.wsdl");
$fID = 1;
$franchises = $client->getFranchises($fID);
$rid= $franchises["Franchises"][1]["Id"];
$rdesc= $franchises["Franchises"][1]["Description"];
print("The id: $rid\n");
print("The description: $rdesc\n");
?>
--------- server -------------
<?php
function getFranchises($pfID)
{
$result = mysql_query("SELECT * FROM tbtest where franchiseID=$pfID");
while($row = mysql_fetch_array($result))
{
$rID=$row['franchiseID'];
$rDesc=$row['franchisedDescription'];
}
mysql_close($con);
return array("Franchises" => array(1=> array("Id"=>$rID, "Description"=>$rDesc)) );
}
ini_set("soap.wsdl_开发者_开发问答cache_enabled", "0");
$server = new SoapServer('apams.wsdl');
$server->addFunction("getFranchises");
$con =mysql_connect("localhost","testuser","******");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$db_selected=mysql_select_db("testdb", $con);
if (!$db_selected) {
die ('Can\'t use testdb : ' . mysql_error());
}
$server->handle();
?>
精彩评论