ds34222222 2011-04-01 21:10
浏览 45

在PHP / WSDL中处理复杂类型

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
");
print("The description: $rdesc
");

?>

--------- 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();
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算