2 hayi123 hayi123 于 2013.11.02 21:36 提问

求解用php做一个web service的相关程序??不知道哪里出问题了?谢谢!!!

<?php

class 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"?>

wsdl:types


xsd:complexType
xsd:sequence

/xsd:sequence
/xsd:complexType
/xsd:element

xsd:complexType
xsd:sequence

/xsd:sequence
/xsd:complexType
/xsd:element
/xsd:schema
/wsdl:types


/wsdl:part
/wsdl:message


/wsdl:message




/wsdl:operation
/wsdl:portType

transport="http://schemas.xmlsoap.org/soap/http" />


wsdl:input

/wsdl:input
wsdl:output

/wsdl:output
/wsdl:operation
/wsdl:binding



/wsdl:port
/wsdl:service
/wsdl:definitions

1个回答

hayi123
hayi123   2013.11.03 19:22

有没有哪位大神帮忙看一下,小弟在此谢过呀!

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!