我正在用soap做php的webservice,出现一个问题,就是wsdl中对数组支持不是很好,我在数据库中查出的数据,用pg_fetch_all($info);做成数组,然后在wsdl中用$soap->wsdl->addComplexType做了一个string的数组,不行,返回类型错误,不知道,为什么,很急,请高手指点
server文件
<?php
header("content-type:text/xml;charset=utf-8");
//header("Content-Type:text/html;charset=UTF-8");
//header("Content-Type:text/xml;charset=UTF-8");
require_once("nusoap.php");
function concatenate($str1) {
//if (is_string($str1) && is_string($str2))
//if (is_string($str1))
$conn=pg_connect("host=********** dbname=****** user=********** password=******* port=*********");
if($conn)
{
echo "connection is ok! ****** !!!!";
}
else
{
echo "something wrong has happened!";
}
$sql="select sku from temp1;";
$info=pg_exec($conn,$sql);
$array = pg_fetch_all($info);
return $array;
// else
// return new soap_fault(' 客户端 ','','concatenate 函数的参数应该是两个字符串 ');
//return array("sfdsfd");
}
function sunxin($str1) {
//if (is_string($str1) && is_string($str2))
//if (is_string($str1))
$conn=pg_connect("host=********** dbname=****** user=********** password=******* port=*********");
if($conn)
{
echo "connection is ok! ********** !!!!";
}
else
{
echo "something wrong has happened!";
}
$sql="select abc from temp1;";
$info=pg_exec($conn,$sql);
$array = pg_fetch_all($info);
return $array;
// else
// return new soap_fault(' 客户端 ','','concatenate 函数的参数应该是两个字符串 ');
//return array("sfdsfd");
}
$soap = new soap_server();
$soap->configureWSDL('AuthorityServicewsdl', 'urn:AuthorityServicewsdl');
//参数设置空间
$soap->wsdl->schemaTargetNamespace = 'urn:AuthorityServicewsdl';
$soap->wsdl->addComplexType('TStringDynArray','complexType','array','','SOAP-ENC:Array',array(),array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'string[]')),'xsd:string');$soap->configureWSDL('concatenate'); // 初始化对 WSDL 的支持
// 注册服务
$soap->register('concatenate',
//array("str1"=>"xsd:string","str2"=>"xsd:string"), // 输入参数的定义
array("str1"=>"xsd:string"),
array("return"=>"xsd:TStringDynArray") // 返回参数的定义
);$soap->register('sunxin',
//array("str1"=>"xsd:string","str2"=>"xsd:string"), // 输入参数的定义
array("str1"=>"xsd:string"),
array("return"=>"xsd:array") // 返回参数的定义
);
$HTTP_RAW_POST_DATA = file_get_contents("php://input");
//$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$soap->service($HTTP_RAW_POST_DATA);?>clinet文件<?php
//header("Content-Type:text/html;charset=UTF-8");
require_once("nusoap.php");
$client = new nusoap_client('http://localhost/php_ws_test/s.php?wsdl',true);
$parameters=array('********');
$str=$client->call('concatenate',$parameters);
//$proxy = $client->getProxy();
//$str=$proxy->concatenate("sss");
//echo strlen($str);
// $client->soap_defencoding = 'utf-8';
// $client->decode_utf8 = false;
// $client->xml_encoding = 'utf-8';
if (!$err=$client->getError()) {
echo "正常";
print_r($str);
} else {
echo " 错误 :".$err;
}
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>
server文件
<?php
header("content-type:text/xml;charset=utf-8");
//header("Content-Type:text/html;charset=UTF-8");
//header("Content-Type:text/xml;charset=UTF-8");
require_once("nusoap.php");
function concatenate($str1) {
//if (is_string($str1) && is_string($str2))
//if (is_string($str1))
$conn=pg_connect("host=********** dbname=****** user=********** password=******* port=*********");
if($conn)
{
echo "connection is ok! ****** !!!!";
}
else
{
echo "something wrong has happened!";
}
$sql="select sku from temp1;";
$info=pg_exec($conn,$sql);
$array = pg_fetch_all($info);
return $array;
// else
// return new soap_fault(' 客户端 ','','concatenate 函数的参数应该是两个字符串 ');
//return array("sfdsfd");
}
function sunxin($str1) {
//if (is_string($str1) && is_string($str2))
//if (is_string($str1))
$conn=pg_connect("host=********** dbname=****** user=********** password=******* port=*********");
if($conn)
{
echo "connection is ok! ********** !!!!";
}
else
{
echo "something wrong has happened!";
}
$sql="select abc from temp1;";
$info=pg_exec($conn,$sql);
$array = pg_fetch_all($info);
return $array;
// else
// return new soap_fault(' 客户端 ','','concatenate 函数的参数应该是两个字符串 ');
//return array("sfdsfd");
}
$soap = new soap_server();
$soap->configureWSDL('AuthorityServicewsdl', 'urn:AuthorityServicewsdl');
//参数设置空间
$soap->wsdl->schemaTargetNamespace = 'urn:AuthorityServicewsdl';
$soap->wsdl->addComplexType('TStringDynArray','complexType','array','','SOAP-ENC:Array',array(),array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'string[]')),'xsd:string');$soap->configureWSDL('concatenate'); // 初始化对 WSDL 的支持
// 注册服务
$soap->register('concatenate',
//array("str1"=>"xsd:string","str2"=>"xsd:string"), // 输入参数的定义
array("str1"=>"xsd:string"),
array("return"=>"xsd:TStringDynArray") // 返回参数的定义
);$soap->register('sunxin',
//array("str1"=>"xsd:string","str2"=>"xsd:string"), // 输入参数的定义
array("str1"=>"xsd:string"),
array("return"=>"xsd:array") // 返回参数的定义
);
$HTTP_RAW_POST_DATA = file_get_contents("php://input");
//$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$soap->service($HTTP_RAW_POST_DATA);?>clinet文件<?php
//header("Content-Type:text/html;charset=UTF-8");
require_once("nusoap.php");
$client = new nusoap_client('http://localhost/php_ws_test/s.php?wsdl',true);
$parameters=array('********');
$str=$client->call('concatenate',$parameters);
//$proxy = $client->getProxy();
//$str=$proxy->concatenate("sss");
//echo strlen($str);
// $client->soap_defencoding = 'utf-8';
// $client->decode_utf8 = false;
// $client->xml_encoding = 'utf-8';
if (!$err=$client->getError()) {
echo "正常";
print_r($str);
} else {
echo " 错误 :".$err;
}
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>
array(),
array(array('ref' => 'SOAP-ENC:arrayType',
'wsdl:arrayType' => 'tns:tableData[]')),
'tns:userData');
$server->wsdl->addComplexType('userData','complexType','struct','all','',
array(
'id' => array('name' => 'id', 'type' => 'xsd:int'),
'username' => array('name' => 'username', 'type' => 'xsd:string')
));soap->register('concatenate',
array("str1"=>"xsd:string"),
array("return"=>"xsd:userDatas") // 返回参数的定义
);