第一次用php写webservice遇到一个很奇怪的有关问题,详细请看内容,有代码

WBOY
Release: 2016-06-13 12:54:19
Original
940 people have browsed it

第一次用php写webservice遇到一个很奇怪的问题,详细请看内容,有代码
1.服务器端代码(service):

<br />
<?php<br />
require_once "../views/config.inc";     // 只要加上一个就报错,用include也一样,其中config.inc 文件很简单加上就报错<br />
$soap = new SoapServer(null,array('uri'=>"http://xxxxxx.com.cn/",'encoding'=>'UTF-8'));<br />
$soap->setClass('user');<br />
$soap->handle();<br />
class user<br />
{<br />
	protected  $Rolse=array();<br />
	public function getRoles($UserName,$Password)<br />
	{<br />
		return $UserName.$Password;<br />
	}<br />
}<br />
?>
Copy after login

2、客户端代码:
<br />
<?php<br />
$roles=array();<br />
try <br />
{<br />
    $client = @new SoapClient(null,<br />
        array('location' =>"http://localhost/models/userInfo.php",'trace'=>1,'encoding'=>'UTF-8','uri' => "http://xxxxxx.com.cn")<br />
    );<br />
    $roles=$client->getRoles('test','12345678');<br />
    print_r($roles);<br />
} <br />
catch (SoapFault $fault)<br />
{<br />
    echo "Error: ",$fault->faultcode,", string: ",$fault->faultstring;<br />
}<br />
?><br />
Copy after login

3.config.inc文件:
<br />
<?php<br />
global $conf;<br />
$conf['DBUSER']='root';<br />
$conf['DBPWD']='';<br />
$conf['DBHOST']='localhost';<br />
?><br />
Copy after login


代码就这些,现在出现非常奇怪的问题:只要我在服务器端代码中加上“require_once "../views/config.inc";”在句,调用它就出错:“looks like we got no XML document”,把这行注释掉,程序就正常,一直没有找到解决办法。
php webservice soap


------解决方案--------------------
可能造成的原因:
1. 所有的php文件,包括直接和间接调用到的,注意在之前不能用任何空行或者空格字符,之后不能有任何空行或空白字符.
2. 程序本身的语法错误―-函数参数少了、少了封号、数据库错误等等的错误,而未使用异常处理来抓住这些错误。
3. 人为的返回了非XML标准的数据,如echo了一个非XML标准字符串等等。

上面是复制的

------解决方案--------------------
不引用,直接放在里面,看如何?
<?php<br /> global $conf;<br /> $conf['DBUSER']='root';<br /> $conf['DBPWD']='';<br /> $conf['DBHOST']='localhost';
?>
------解决方案--------------------
config.inc
<?php<br />
global $conf;<br />
$conf['DBUSER']='root';<br />
$conf['DBPWD']='';<br />
$conf['DBHOST']='localhost';
Copy after login
以 ANSI 保存

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template