SOAP

<?php
//person.class.php文件
class person
{
	 public function getInfo()
	 {
	 	$strGetList = 'SELECT * FROM information LIMIT 100';
	 	$GLOBALS['le']->query($strGetList);
	 	$results = array();
	 	$xmlString = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
	 	$xmlString .="<Data>\n";
	 	while( $rows = $GLOBALS['le']->fetch_assoc() ) {
	 		$results[] = $rows;
	 	}
	 	foreach($results as $key=>$val) {
	 		$xmlString .="<Rec ID='UU{$key}'>\n";
	 		foreach($val as $k=>$v ) {
	 			if(strlen($v)>0) {
	 				$v = htmlspecialchars($v);
		 			$xmlString .=" <UU{$k}>$v</UU{$k}>\n";
		 		}
	 		}
	 		$xmlString .="</Rec>\n";
	 	}
	 	$xmlString .="</Data>\n";
	 	return $xmlString;
	 }
}
//$p = new person;
//echo $p->getInfo();//经测试xml中可以显示所有数据

--- 分割线 ---

<?php
//server.php文件
include("person.class.php");
$server = new SoapServer(null,array('uri'=>'abcd','encoding'=>'UTF-8'));
$server->setClass('person');
$server->handle();

--- 分割线 ---

<?php
//client.php文件
try{
	$soap = new SoapClient(null,array(
		'location'=>'http://192.168.1.126:102/server.php',
		'uri'=>'abcd',
 		'encoding' => 'UTF-8',
	));
	$s1 =$soap->__soapCall('getInfo',array());
	echo $s1;
} catch(Exction $e) {
	echo $e->getMessage();
}

  今天在想使用soap开发相关接口给合作的公司调用,但是遇到了这个错误。排查了很久,在google也查了很久,但都不是我所遇到的问题。不过我最终错误发现跟soapserver传输的数据量的大小有关系(不知道这个描述是否恰当)。当我从数据库取10条数据,那么就可以很容易的使用soapclient获取到数据,但是当我从数据库里查询1000条数据的时候就会报错了(“Fatal error: Uncaught SoapFault exception: [Client] looks like we got no XML document in……”)!如果我直接运行person.class.php程序是可以显示完整的xml文档的。这根服务器的环境配置会有关系吗?我对于soap认识并不深,也只是现学现卖。希望有经验的前辈们可以指点一二。多谢了!
以下是我的程序代码:

posted on 2014-10-05 11:32  3649  阅读(150)  评论(0编辑  收藏  举报

导航