จากนั้นก็แบ่งโค๊ดออกเป็น 2 ส่วนเหมือนเดิม
โดยส่วนแรกจะเป็นส่วนของ Server จะเป็นไปตามโค๊ดด้านล่างนี้
โค้ด: เลือกทั้งหมด
require('Zend/Soap/AutoDiscover.php');
require('Zend/Soap/Server.php');
function hello($input) {
return "Hello".$input;
}
if(isset($_GET['wsdl'])) {
$autodiscover = new Zend_Soap_AutoDiscover();
$autodiscover->addFunction('hello');
$autodiscover->handle();
}else{
$server = new Zend_Soap_Server( 'http://localhost/***/yyy.php?wsdl' );
$server->addFunction("hello");
$server->handle();
}
จากโค๊ดดังกล่าว ส่วนแรกจะเป็นการดึง library ที่จะใช้ในส่วนของ Server โดยเราจะดึงมา 2 ไฟล์ตามนี้
โค้ด: เลือกทั้งหมด
require('Zend/Soap/AutoDiscover.php')
require('Zend/Soap/Server.php')
ต่อมาจะสังเกตุได้ว่าโค๊ดได้ถูกแบ่งออกเป็น 2 ส่วนคือ
โค้ด: เลือกทั้งหมด
$autodiscover = new Zend_Soap_AutoDiscover();
$autodiscover->addFunction('hello');
$autodiscover->handle();
โค้ด: เลือกทั้งหมด
$server = new Zend_Soap_Server( 'http://localhost/***/yyy.php?wsdl' );
$server->addFunction("hello");
$server->handle();
ส่วนต่อมาจะเป็นส่วนของ Client จะมีโค๊ดดังนี้
โค้ด: เลือกทั้งหมด
require('Zend/Soap/Client.php');
$client = new Zend_Soap_Client( 'http://localhost/***/yyy.php?wsdl' );
echo( $client->__call( 'hello', array( 'kdkdik' ) ) );
แล้วจึงเป็นการสร้าง Client โดยใช้ไฟล์ WSDL ที่ได้ทำการเจ็นจากส่วน Server
สุดท้ายเป็นการเรียกใช้ฟังก์ชัน
ข้อมูลเพิ่มเติมสำหรับรายละเอียดปลีกย่อยอื่นๆตามลิงค์นี้http://framework.zend.com/manual/en/zend.soap.html