|
|
|
php กับ web service ขอคำปรึกษาเรื่องการ return array ใน webservice ครับ |
|
|
|
|
|
|
|
ตามหัวข้อเลยครับผมมีปัญหา ต้องการ return array ไปยัง client ครับแต่มันไม่สามารถ return ออกไปได้ แต่ถ้าเอาทีละค่าสามารถทำได้ครับ ท่านใดมีความรู้ชี้แนะหน่อยครับ ขอบคุณครับ โค๊ดด้านล่างนี้ครับ
ฝั่ง server
PHP Code
require_once("lib/nusoap.php");
//Create a new soap server
$server = new soap_server();
//Define our namespace
$namespace = "http://localhost:81/webservice/index.php";
$server->wsdl->schemaTargetNamespace = $namespace;
//Configure our WSDL // set title
$server->configureWSDL("HelloWorld");
////////////////// register method for sale summary //////////////////////////
$salecondition = array(
'year' => "xsd:int",
'monthfrom' => "xsd:int",
'monthto' => "xsd:int",
'team' => "xsd:string"
);
$server->register('SaleSummaryReport', $salecondition, array('return' => 'xsd:string'));
function SaleSummaryReport($year, $monthfrom, $monthto, $team)
{
// connect to SQL Server
$conn = mssql_connect("10.0.4.2", "nattapone", "04natt");
mssql_select_db("CoinMIS", $conn);
$p_all = 1;
$proc = mssql_init("RE_TEAM_MON_2005");
mssql_bind($proc, '@saleyear', $year, SQLINT4);
mssql_bind($proc, '@salemonth', $monthfrom, SQLINT4);
mssql_bind($proc, '@salemonth2', $monthto, SQLINT4);
mssql_bind($proc, '@team', $team, SQLVARCHAR);
mssql_bind($proc, '@p_all', $p_all, SQLINT4);
mssql_bind($proc, '@c01', $c01, SQLVARCHAR);
mssql_bind($proc, '@c02', $c02, SQLVARCHAR);
mssql_bind($proc, '@c03', $c03, SQLVARCHAR);
mssql_bind($proc, '@c04', $c04, SQLVARCHAR);
mssql_bind($proc, '@c05', $c05, SQLVARCHAR);
mssql_bind($proc, '@c06', $c06, SQLVARCHAR);
mssql_bind($proc, '@c07', $c07, SQLVARCHAR);
mssql_bind($proc, '@c08', $c08, SQLVARCHAR);
mssql_bind($proc, '@c09', $c09, SQLVARCHAR);
mssql_bind($proc, '@c10', $c10, SQLVARCHAR);
mssql_bind($proc, '@c11', $c11, SQLVARCHAR);
mssql_bind($proc, '@c12', $c12, SQLVARCHAR);
mssql_bind($proc, '@c13', $c13, SQLVARCHAR);
mssql_bind($proc, '@c14', $c14, SQLVARCHAR);
mssql_bind($proc, '@cA', $cA, SQLVARCHAR);
mssql_bind($proc, '@cB', $cB, SQLVARCHAR);
// execute
$result = mssql_execute($proc);
$data = array();
while($row = mssql_fetch_assoc($result))
{
$data[] = $row['area'];
}
return $data;
}
// Get our posted data if the service is being consumed
// otherwise leave this data blank.
$POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';
// pass our posted data (or nothing) to the soap service
$server->service($POST_DATA);
exit();
ฝั่ง Client
Code
require_once("lib/nusoap.php");
$client = new nusoap_client("http://localhost:81/webservice/webserviceserver.php?wsdl",true);
$params = array(
'year'=> 2012,
'monthfrom'=> 5,
'monthto' => 5,
'team' => '92'
);
$data = $client->call("SaleSummaryReport", $params);
if(is_array($data))
{
foreach($data as $area)
{
echo $area;
}
}
else
{
echo "Not have value in array";
}
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2012-05-17 16:30:45 |
By :
nottp106 |
View :
5749 |
Reply :
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เพิ่มอันนี้เข้าไปใน Server ครับ
Code (PHP)
$server->register('HelloWorld',$varname, array('return' => 'tns:ArrayOfString'));
$server->wsdl->addComplexType("ArrayOfString",
"complexType",
"array",
"",
"SOAP-ENC:Array",
array(),
array(array("ref"=>"SOAP-ENC:arrayType","wsdl:arrayType"=>"xsd:string[]")),
"xsd:string");
เดียวจัดเป็นบทความให้ครับ
|
|
|
|
|
Date :
2012-05-17 17:04:49 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
น่าจะได้เป็นแบบนี้ครับ
Code (PHP)
require_once("lib/nusoap.php");
//Create a new soap server
$server = new soap_server();
//Define our namespace
$namespace = "http://localhost:81/webservice/index.php";
$server->wsdl->schemaTargetNamespace = $namespace;
//Configure our WSDL // set title
$server->configureWSDL("HelloWorld");
////////////////// register method for sale summary //////////////////////////
$salecondition = array(
'year' => "xsd:int",
'monthfrom' => "xsd:int",
'monthto' => "xsd:int",
'team' => "xsd:string"
);
$server->register('SaleSummaryReport',$salecondition, array('return' => 'tns:ArrayOfString'));
$server->wsdl->addComplexType("ArrayOfString",
"complexType",
"array",
"",
"SOAP-ENC:Array",
array(),
array(array("ref"=>"SOAP-ENC:arrayType","wsdl:arrayType"=>"xsd:string[]")),
"xsd:string");
function SaleSummaryReport($year, $monthfrom, $monthto, $team)
{
// connect to SQL Server
$conn = mssql_connect("10.0.4.2", "nattapone", "04natt");
mssql_select_db("CoinMIS", $conn);
$p_all = 1;
$proc = mssql_init("RE_TEAM_MON_2005");
mssql_bind($proc, '@saleyear', $year, SQLINT4);
mssql_bind($proc, '@salemonth', $monthfrom, SQLINT4);
mssql_bind($proc, '@salemonth2', $monthto, SQLINT4);
mssql_bind($proc, '@team', $team, SQLVARCHAR);
mssql_bind($proc, '@p_all', $p_all, SQLINT4);
mssql_bind($proc, '@c01', $c01, SQLVARCHAR);
mssql_bind($proc, '@c02', $c02, SQLVARCHAR);
mssql_bind($proc, '@c03', $c03, SQLVARCHAR);
mssql_bind($proc, '@c04', $c04, SQLVARCHAR);
mssql_bind($proc, '@c05', $c05, SQLVARCHAR);
mssql_bind($proc, '@c06', $c06, SQLVARCHAR);
mssql_bind($proc, '@c07', $c07, SQLVARCHAR);
mssql_bind($proc, '@c08', $c08, SQLVARCHAR);
mssql_bind($proc, '@c09', $c09, SQLVARCHAR);
mssql_bind($proc, '@c10', $c10, SQLVARCHAR);
mssql_bind($proc, '@c11', $c11, SQLVARCHAR);
mssql_bind($proc, '@c12', $c12, SQLVARCHAR);
mssql_bind($proc, '@c13', $c13, SQLVARCHAR);
mssql_bind($proc, '@c14', $c14, SQLVARCHAR);
mssql_bind($proc, '@cA', $cA, SQLVARCHAR);
mssql_bind($proc, '@cB', $cB, SQLVARCHAR);
// execute
$result = mssql_execute($proc);
$data = array();
while($row = mssql_fetch_assoc($result))
{
$data[] = $row['area'];
}
return $data;
}
// Get our posted data if the service is being consumed
// otherwise leave this data blank.
$POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';
// pass our posted data (or nothing) to the soap service
$server->service($POST_DATA);
exit();
|
|
|
|
|
Date :
2012-05-17 17:06:16 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
โอ้วได้แล้วครับ แค่เพิ่ม code ที่พี่วินบอกใช่ไหมครับ? ถ้าติดจะเข้ามาถามอีกนะครับ :D
|
|
|
|
|
Date :
2012-05-17 17:19:53 |
By :
nottp106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ใช่ครับ ง่าย ๆ
|
|
|
|
|
Date :
2012-05-17 17:23:01 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เยี่ยมเลยครับพี่ ^^
|
|
|
|
|
Date :
2012-05-18 12:02:35 |
By :
nottp106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|