|
|
|
Nusoap+php ช่วยตรวจสอบ Code ให้หน่อยครับ ว่าควรต้องปรับหรือ เพิ่ม อะไรอีกบ้างคับ |
|
|
|
|
|
|
|
Web Service
<?php
require_once('lib/nusoap.php');
//$NAMESPACE = 'Library';
$server = new soap_server();
//$NAMESPACE = "http://127.0.0.1/nusoap2/library_server.php";
$NAMESPACE = 'Library';
$server->wsdl->schemaTargetNamespace = $NAMESPACE;
$server->configureWSDL('Books', $NAMESPACE);
//$server->configureWSDL('Books', 'urn:Books_wsdl');
$server->wsdl->addComplexType(
'Book',
'complexType',
'struct',
'all',
'',
array(
'author' => array('name'=>'author','type'=>'xsd:string'),
'title' => array('name'=>'title','type'=>'xsd:string'),
'booktitle' => array('name'=>'booktitle','type'=>'xsd:string'),
'isbn' => array('name'=>'isbn','type'=>'xsd:string'),
'publish' => array('name'=>'publish','type'=>'xsd:string'),
'pubyear' => array('name'=>'pubyear','type'=>'xsd:string'),
'price' => array('name'=>'price','type'=>'xsd:string'),
'at' => array('name'=>'at','type'=>'xsd:string')
)
);
$server->wsdl->addComplexType(
'BookArray',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:Book[]')
),
'tns:Book'
);
$server->wsdl->addComplexType(
'Result',
'complexType',
'struct',
'all',
'',
array(
'Result'=>array('name'=>'Result','type'=>'tns:BookArray')
)
);
//$varname = array(
// 'cate' => "xsd:string",
// 'keyword' => "xsd:string",
// );
$server->register('findResult',
array('cate'=>'xsd:string','keyword'=>'xsd:string'),
//$varname,
array('return'=>'tns:Result'),
$NAMESPACE);
function findResult($cate,$keyword)
{
require_once("connection.php");
$filter="";
$arr=array();
//if($r=="history"){
if($cate=="author"){
$filter=" and au.autname like '%".$keyword."%'";
}else if($cate=="title"){
$filter=" and b.title like '%".$keyword."%'";
}else if($cate=="isbn"){
$filter=" and b.isbn='".$keyword."'";
}else{
$filter=" and (au.autname='%".$keyword."%' or b.title like '%".$keyword."%' or b.isbn='".$keyword."')";
}
//mysql_query("SET NAMES tis620");
$sql="SELECT b.bookcode,au.autcode,b.title,au.autname,b.isbn,pb.pubname,pubyear,price,cbooktitle FROM book as b left join autcat as ac on b.bookcode=ac.bookcode left join author as au on ac.autcode=au.autcode left join publishs as pb on b.pubcode=pb.pubcode where 1 {$filter} ";
$result=mysql_query ($sql);
$cnt=mysql_num_rows($result);
if($cnt>0){
$i=0;
while($data=mysql_fetch_object($result)){
$arr[$i]["author"]=$data->autname;
$arr[$i]["title"]=$data->title;
$arr[$i]["booktitle"]=$data->cbooktitle;
$arr[$i]["isbn"]=$data->isbn;
$arr[$i]["publish"]=$data->pubname;
$arr[$i]["pubyear"]=$data->pubyear;
$arr[$i]["price"]=$data->price;
$arr[$i]["at"]="London";
$i++;
}
}
// }
$result=array("Result"=>$arr);
return $result;
}
// Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
exit();
?>
Tag : PHP, Web Service
|
|
|
|
|
|
Date :
2015-01-19 16:23:16 |
By :
phetzzy99 |
View :
875 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Find
<?
session_start();
set_time_limit(0);
require_once('lib/nusoap.php');
include("connection.php");
?>
<HTML>
<HEAD>
<TITLE>System Management Video Central Library </TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=tis-620">
<style>
body{
margin:0;
background:#6198C0;
}
body,table{
font-family: sans-serif;
font-size: 12px;
}
.link{
background:white;
}
</style>
</HEAD>
<BODY BGCOLOR=#FFFFFF LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
<!-- ImageReady Slices (digital.psd) -->
<TABLE WIDTH=800 BORDER=0 align="center" CELLPADDING=0 CELLSPACING=0 bgcolor="#94DDF4">
<!--DWLayoutTable-->
<TR>
<TD height="135" COLSPAN=3 valign="top" bgcolor="#FFFFFF"><img src="images/11.gif" width="800" height="135"></TD>
</TR>
<TR>
<TD width="13" height="468"> </TD>
<TD width="773" valign="top" align="center" bgcolor="#FFFFFF">
<form action="find.php" method="post">
<input type="hidden" name="hidden_submit" value="yes">
ค้นจาก : <input type="text" name="keyword" value="<?=isset($keyword)?$keyword:""?>">
: <select name="cate">
<option value="All">ทั้งหมด</option>
<option value="author" <?=isset($cate)&&$cate=="author"?"selected":""?>>ชื่อผู้แต่ง</option>
<option value="title" <?=isset($cate)&&$cate=="title"?"selected":""?>>ชื่อเรื่อง</option>
<option value="isbn" <?=isset($cate)&&$cate=="isbn"?"selected":""?>>isbn</option>
<!--option value="All">All</option-->
</select>
<input type="submit" value=" ค้นหา ">
</form>
<!-----------------------------------XML-File------------------------------------------------------->
<?php
function wrietFile($source,$id){
$file=fopen("./xml/WSservice{$id}.xml","w+");
fputs($file,$source);
fclose($file);
}
function rp($str,$charSearch,$charReplace){
return str_replace($charSearch,$charReplace,$str);
}
if(isset($_POST["keyword"]) || isset($_GET["keyword"])){
$id=session_id();
$cate="";
$keyword="";
if(isset($_POST["keyword"])){
$keyword=$_POST["keyword"];
}
if(isset($_GET["keyword"])){
$keyword=$_GET["keyword"];
}
if(isset($_POST["cate"])){
$cate=$_POST["cate"];
}
if(isset($_GET["cate"])){
$cate=$_GET["cate"];
}
//แก้ไขใน 2 บรรทัดล่างนี้ให้ตรงกับโปรแกรมรัน
$xml="<?xml version='1.0' encoding='tis-620' ?>\n";
$xml.="<Book>\n";
$sql="select * from service";
$rs=mysql_query($sql);
$a_result=array();
$i=0;
$array_keys=array();
while($row=mysql_fetch_object($rs)){
$client = new nusoap_client($row->service_access_point);
$a_result[$i]=$client->call($row->service_name,array("{$row->parameter1}"=>$cate,"{$row->parameter2}"=>$keyword));
$array_keys[$i]["output"]=$row->ws_output;
$array_keys[$i]["parameter1"]=$row->parameter1;
$array_keys[$i]["parameter2"]=$row->parameter2;
$array_keys[$i]["author"]=$row->ws_author;
$array_keys[$i]["title"]=$row->ws_title;
$array_keys[$i]["booktitle"]=$row->ws_booktitle;
$array_keys[$i]["isbn"]=$row->ws_isbn;
$array_keys[$i]["pubyear"]=$row->ws_pubyear;
$array_keys[$i]["price"]=$row->ws_price;
$array_keys[$i]["at"]=$row->ws_at;
print_r($a_result[$i]);
echo var_dump($array_keys[$i]);
$i++;
}
$iIndex=0;
foreach($a_result as $val){
$data=$val[$array_keys[$iIndex]["output"]];
for($i=0;$i<count($data);$i++){
$xml.="<row>\n";
$xml.="<author value=\"".rp($data[$i][$array_keys[$iIndex]["author"]],"&","&")."\" />\n";
//$xml.="<title value=\"".rp($data[$i][$array_keys[$iIndex]["title"]],"&","&")."\" />\n";
//$xml.="<booktitle value=\"".rp($data[$i][$array_keys[$iIndex]["booktitle"]],"&","&")."\" />\n";
//$xml.="<isbn value='{$data[$i][$array_keys[$iIndex]["isbn"]]}' />\n";
//$xml.="<publish value=\"".rp($data[$i][$array_keys[$iIndex]["publish"]],"&","&")."\" />\n";
//$xml.="<pubyear value='{$data[$i][$array_keys[$iIndex]["pubyear"]]}' />\n";
//$xml.="<price value='{$data[$i][$array_keys[$iIndex]["price"]]}' />\n";
//$xml.="<at value=\"".rp($data[$i][$array_keys[$iIndex]["at"]],"&","&")."\" />\n";
$xml.="</row>\n";
}
$iIndex++;
}
$xml.="</Book>";
wrietFile($xml,$id);
echo var_dump($data[$i]);
?>
<!-----------------------------------XML-File------------------------------------------------------->
<table width="98%" bgcolor="#FFC0C0" cellpadding="0" cellspacing="0" border="1" bordercolor="#444444">
<tr bgcolor="#33FF99">
<th align="center">ลำดับ</th>
<th align="center">ผู้แต่ง</th>
<th align="center">ชื่อเรื่อง</th>
<th align="center">หัวเรื่อง</th>
<th align="center">ISBN</th>
<th align="center">สถานที่พบ</th>
<th align="center">รายละเอียด</th>
</tr>
<?
$realpath=realpath(".");
$file=$realpath."/xml/WSservice{$id}.xml";
$sXml=simplexml_load_file($file);
$page=1;
if(isset($_GET["page"])){
$page=$_GET["page"];
}
$ix=1;
$limit=10;
$start=($page-1)*$limit;
$cnt=count($sXml->row);
$pageCount=ceil($cnt/$limit);
$bg="#FFFFC0";
$data=$sXml->row;
for($i=$start;$i<$cnt;$i++){
if($ix>$limit){
break;
}
if($i%2==0){
$bg="#FFFFC0";
}else{
$bg="#C0FFFF";
}
$aAuthor=$data[$i]->author->attributes();
$aTitle=$data[$i]->title->attributes();
$aBooktitle=$data[$i]->booktitle->attributes();
$aIsbn=$data[$i]->isbn->attributes();
$aPublish=$data[$i]->publish->attributes();
$aPubyear=$data[$i]->pubyear->attributes();
$aPrice=$data[$i]->price->attributes();
$aAt=$data[$i]->at->attributes();
$vAuthor=$aAuthor["value"];
$vTitle=$aTitle["value"];
$vBooktitle=$aBooktitle["value"];
$vIsbn=$aIsbn["value"];
$vPublish=$aPublish["value"];
$vPubyear=$aPubyear["value"];
$vPrice=$aPrice["value"];
$vAt=$aAt["value"];
$author=iconv("utf-8","tis-620",$vAuthor);
$title=iconv("utf-8","tis-620",$vTitle);
$booktitle=iconv("utf-8","tis-620",$vBooktitle);
$publish=iconv("utf-8","tis-620",$vPublish);
$at=iconv("utf-8","tis-620",$vAt);
?>
<tr bgcolor="<?=$bg?>">
<td align="center"><?=$i+1?></td>
<td> <?=$author==""?$vAuthor:$author?></td>
<td> <?=$title==""?$vTitle:$title?></td>
<td> <?=$booktitle==""?$vBooktitle:$booktitle?></td>
<td> <?=$vIsbn?></td>
<td> <?=$at==""?$vAt:$at?></td>
<td> <a href="detail.php?row=<?=$i?>&id=<?=$id?>" target="_blank">Detail</a></td>
</tr>
<?
$ix++;
} ?>
</table>
<div class="link">
<?
for($x=1;$x<=$pageCount;$x++){
if($x==$page){
echo "<b>{$x}</b> ";
}else{
echo "<a href='find.php?keyword={$keyword}&cate={$cate}&page={$x}'>{$x}</a> ";
}
}
}
?>
</div>
</TD>
<TD width="14"> </TD>
</TR>
<TR>
<TD height="19" COLSPAN=3 valign="top" bgcolor="#50C6ED"><!--DWLayoutEmptyCell--> </TD>
</TR>
</TABLE>
<!-- End ImageReady Slices -->
</BODY>
</HTML>
|
|
|
|
|
Date :
2015-01-19 16:24:09 |
By :
phetzzy99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มันไม่แสดงข้อมูลออกมาเลยคับ
|
ประวัติการแก้ไข 2015-01-19 22:26:29
|
|
|
|
Date :
2015-01-19 18:53:44 |
By :
phetzzy99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|