问题描述
- 求解用php做一个web service的相关程序??不知道哪里出问题了?谢谢!!!
-
<?phpclass soap
{
private $tel;
private $num;
public function Book($tel,$num)
{
file_put_contents("d:/mylog.log",$tel,FILE_APPEND);
$this->tel=$tel;
$this->num=$num;//????$conn=mysql_connect("localhost","root",""); if(!$conn) { die("连接数据库失败".mysql_error()); } mysql_query("set names utf8",$conn)or die(mysql_errno()); mysql_select_db("myorder",$conn) or die(mysql_errno()); $sql="insert into mytable (tel,num) values('$tel','$num')"; $res=mysql_query($sql,$conn)or die(mysql_error()); if(!$res) { //die("操作失败".mysql_error()); return false; } return TRUE; mysql_close($conn); }
}
?>
服务端:
<?php
ini_set("soap.wsdl_cache_enabled", "0");
require_once 'order.php';
$ser=new SoapServer('soap.wsdl',array('soap_version' => SOAP_1_2)); //创建SoapServer对象
$ser->setClass("soap");
$ser->handle();
?>客户端:
<?php
try{
ini_set("soap.wsdl_cache_enabled", "0");
$tel=$_POST['tel'];
$num=$_POST['num'];
$client=new SoapClient("soap.wsdl");
//echo $tel;
//$tel="13245678900";
//$num="22";
echo $tel;
$result=$client->Book("$tel","$num");//这句有问题if($result) { echo "注册成功!"; } else echo "注册失败!";
}catch (SoapFault $e)
{
echo $e->getMessage();
}catch (Exception $e)
{
echo $e->getMessage();
}
?>
以及WSDL文件:<?xml version="1.0" encoding="UTF-8" standalone="no"?>
/xsd:sequence
/xsd:complexType
/xsd:element/xsd:sequence
/xsd:complexType
/xsd:element
/xsd:schema
/wsdl:types/wsdl:part
/wsdl:message/wsdl:message
/wsdl:operation
/wsdl:portTypetransport="http://schemas.xmlsoap.org/soap/http" />
/wsdl:input
wsdl:output/wsdl:output
/wsdl:operation
/wsdl:binding/wsdl:port
/wsdl:service
/wsdl:definitions
解决方案
有没有哪位大神帮忙看一下,小弟在此谢过呀!