从java调用php web服务

时间:2012-08-29 01:38:59

标签: java php web-services wsdl

我有下面的php webservice代码,我想做什么,以便我可以在java中调用这个web服务。 我需要先生成wsdl吗?然后使用wsdl生成java Web服务存根?我怎么能在java中调用它。我需要使用什么工具。谢谢。

<?php include_once("../../lib/config.php"); ?>
<?php
if(!extension_loaded("soap")){
  dl("php_soap.dll");
}

ini_set("soap.wsdl_cache_enabled","0");
$server = new SoapServer("membersearch.wsdl");

function doMyMemberSearch($membernumber){

    $sqlMemberInfo = mysql_query("SELECT * FROM Member_Info WHERE Member_Number = '".$membernumber."'");
    $rowMemberInfo = mysql_fetch_array($sqlMemberInfo);

  $arr[] = array(
           "anniversary" => $rowMemberInfo['Anniversary'],
           "club"  => $rowMemberInfo['Club'],
           "level"=> $rowMemberInfo['Level'],
           "delivery"=> $rowMemberInfo['Delivery'],
           "firstname"=> $rowMemberInfo['First_Name'],
           "lastname"=> $rowMemberInfo['Last_Name'],
           "birthday"=> $rowMemberInfo['Birthday'],
           "spousefirst"=> $rowMemberInfo['Spouse_First'],
           "spouselast"=> $rowMemberInfo['Spouse_Last'],
           "spousebirthday"=> $rowMemberInfo['Spouse_Birthday'],
           "signuploc"=> $rowMemberInfo['Signup_Loc'],
           "status"=> $rowMemberInfo['Status']

         );
             if (isset($rowMemberInfo['Anniversary'])) {
                 return $arr;
             }else {
                 throw new SoapFault("Server","Unknown Member Number '$membernumber'.");
         }
}




$server->AddFunction("doMyMemberSearch");
$server->handle();
?>

1 个答案:

答案 0 :(得分:0)

WSDL与实现语言无关。因此,它是用PHP,C#,Java还是任何其他语言编写的并不重要。 您需要获取该服务的.wsdl文件。通常,您可以通过将浏览器指向服务URL并添加查询字符串'?WSDL'来获得该结果。

示例:

http://www.example.com/theWebService?WSDL

完成后,您可以使用Apache CXF,Apache Axis2,Spring WS或任何其他Web服务框架来生成Java客户端存根代码。