Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,030

HOME > PHP > PHP Forum > อยากเรียก database ผ่านทาง webservice (nusoap) ครับช่วยหน่อย



 

อยากเรียก database ผ่านทาง webservice (nusoap) ครับช่วยหน่อย

 



Topic : 053953



โพสกระทู้ ( 38 )
บทความ ( 0 )



สถานะออฟไลน์




ต้องการทำเว็บเซอวิสที่เรียกฐานข้อมูลจาก mysql โดยใช้ nusoap ตอนนี้สร้างทั้งฝั่ง server และ client เสร็จแล้ว แต่ตอนเรียกใช้ client ฟ้องว่า Fatal error: Call to undefined method soapclient::getCustomer() in C:\AppServ\www\nusoap\cu_client.php on line 23
ครับ
ฝั่้งเซอเวอร์
Code (PHP)
<?php
	include('lib/nusoap.php');
	//Set no cache WSDL
	ini_set("soap.wsdl_cache_enabled", "0");
	
	//service function
	function getCustomer($Value){
		
		//connect database
		//require_once('conndb.php');
		$objConnect = mysql_connect("localhost","root","12345678") or die("Error Connect to Database");
		$objDB = mysql_select_db("test");
		mysql_query("SET NAMES UTF8");
		$str = "SELECT * FROM cu_table WHERE cu_id = $Value";
		$query = mysql_query($str);
		
		while($Result = mysql_fetch_array($query))
		{
			$Value = $Result['cu_company'];
			return $Value;
		/*$cu_company = $result['cu_company'];
			$cu_name = $result['cu_name'];
			$cu_ad1 = $result['cu_ad1'];
			$cu_ad2 = $result['cu_ad2'];
			$cu_ad3 = $result['cu_ad3'];
			$cu_ad4 = $result['cu_ad4'];
			$cu_ad5 = $result['cu_ad5'];
			$cu_ad6 = $result['cu_ad6'];
			$cu_tel = $result['cu_tel'];
			return $cu_id;
			return $cu_company;
			return $cu_name;
			return $cu_ad1;
			return $cu_ad2;
			return $cu_ad3;
			return $cu_ad4;
			return $cu_ad5;
			return $cu_ad6;
			return $cu_tel;*/
		}
	}
	
	//create server instance
	$server = new SoapServer("customerwsdl.wsdl");
	
	//add function
	$server->addFunction("getCustomer");
	
	//handle server with client
	$server->handle();
?>



ฝั่ง client
Code (PHP)
<?php header("Content-Type:text/html; charset=utf-8");?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test Webservice,PHP</title>
</head>

<body>
<?php
include('lib/nusoap.php');
	//create client instance
	$client = new SoapClient("http://localhost/nusoap/testwsdl.wsdl");
	
	/*echo '<h3>รายชื่อ Function</h3>';
	$funcs = $client->__getFunctions();
	
	foreach($funcs as $func)
	{
		echo $func, '<br>';
	}*/
	
	echo $client->getCustomer(1);
?>
</body>
</html>



WSDL
Code (PHP)
<?xml version ='1.0' encoding ='utf-8' ?>
<definitions name='getCustomer'
  targetNamespace='http://example.org/plus'
  xmlns:tns=' http://example.org/plus '
  xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
  xmlns:xsd='http://www.w3.org/2001/XMLSchema'
  xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'
  xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
  xmlns='http://schemas.xmlsoap.org/wsdl/'>

  <!-- For getCustomer Function -->
  <message name='getCustomerRequest'>
    <part name='Value' type='xsd:integer'/>
  </message>
  <message name='getCustomerResponse'>
    <part name='Result' type='xsd:string'/>
  </message>

  <!-- For second Function2 -->
  <!--<message name='substractRequest'>
    <part name='num1' type='xsd:float'/>
    <part name='num2' type='xsd:float'/>
  </message>
  <message name='substractResponse'>
    <part name='Result' type='xsd:float'/>
  </message>-->

  <portType name='getCustomerPortType'>
    <operation name='getcustomer'>
      <input message='tns:getCustomerRequest'/>
      <output message='tns:getCustomerResponse'/>
    </operation>
  </portType>
  
  <!-- For portType of Function2-->
  <!--<portType name='substractPortType'>
    <operation name='substract'>
      <input message='tns:substractRequest'/>
      <output message='tns:substractResponse'/>
    </operation>
  </portType>-->

  <binding name='getCustomerBinding' type='tns:getCustomerPortType'>
    <soap:binding style='rpc'
      transport='http://schemas.xmlsoap.org/soap/http'/>
    <operation name='getcustomer'>
      <soap:operation soapAction='urn:xmethods-delayed-quotes#plus'/>
      <input>
        <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
          encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
      </input>
      <output>
        <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
          encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
      </output>
    </operation>
  </binding>
  
  <!-- Binding for function2 -->
  <!--<binding name='substractBinding' type='tns:substractPortType'>
    <soap:binding style='rpc'
      transport='http://schemas.xmlsoap.org/soap/http'/>
    <operation name='substract'>
      <soap:operation soapAction='urn:xmethods-delayed-quotes#substract'/>
      <input>
        <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
          encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
      </input>
      <output>
        <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
          encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
      </output>
    </operation>
  </binding>-->

  <service name='getCustomerService'>
    <port name='getCustomerPort' binding='getCustomerBinding'>
      <soap:address location='http://localhost/nusoap/cu_nusoup.php'/>
    </port>
  </service>
  
  <!-- Service for function2 -->
  <!--<service name='substractService'>
    <port name='substractPort' binding='substractBinding'>
      <soap:address location='http://localhost/nusoap/cu_nusoup.php'/>
    </port>
  </service>-->
</definitions>





Tag : PHP, MySQL, CakePHP, WebService







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2011-01-04 17:35:30 By : oceanbluest View : 3506 Reply : 3
 

 

No. 1

Guest


$client->call('getCustomer',$param);






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-02-06 17:58:25 By : xxx
 


 

No. 2



โพสกระทู้ ( 869 )
บทความ ( 2 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


ต้อง register function getCustomer หรือเปล่าครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-03-08 10:14:18 By : onedan
 

 

No. 3



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook



สามารถใช้ nusoap และ SoapClient ใน php เพื่อเรียก Web Server ได้แบบง่าย ๆ ครับ

Go to : PHP - Calling .NET Web Service ใช้ PHP เรียกเว็บเซอร์วิส ของ .NET ด้วย nusoap
Go to : PHP กับ SoapClient และเรียกเว็บเซอร์วิส ของ ASP.NET Web Service (php_soap.dll)
Go to : PHP Create - Call Web Service สร้างและเรียกเว็บเซอร์วิส ด้วย PHP (NuSoap and Soap)
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-03-26 07:05:01 By : webmaster
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : อยากเรียก database ผ่านทาง webservice (nusoap) ครับช่วยหน่อย
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่