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,027

HOME > PHP > PHP Forum > มีปัญหาเรื่องการเขียน php เพื่อส่งข้อมูลไปยัง web service ค่ะ



 

มีปัญหาเรื่องการเขียน php เพื่อส่งข้อมูลไปยัง web service ค่ะ

 



Topic : 075969

Guest




ได้ทำการส้รางweb service ด้วยจาวา โดยใช้eclipseค่ะ ได้ลองรันในeclipseแล้วก็สามารถส่งข้อมูลได้ปกติ แต่พอมาลองในlocalhostแล้วใช้ไม่ได้ค่ะ

มันขึ้นว่า Exception occurred while trying to invoke service method findID ตลอดเลย

http://localhost:8080/axis2/services/DBAccess?wsdl
<wsdl:definitions targetNamespace="http://ws.apache.org/axis2"><wsdl:documentation>
		Please Type your service description here
	</wsdl:documentation><wsdl:types><xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://ws.apache.org/axis2"><xs:element name="findID"><xs:complexType><xs:sequence><xs:element minOccurs="0" name="id" nillable="true" type="xs:string"/></xs:sequence></xs:complexType></xs:element><xs:element name="findIDResponse"><xs:complexType><xs:sequence><xs:element minOccurs="0" name="return" nillable="true" type="xs:anyType"/></xs:sequence></xs:complexType></xs:element></xs:schema></wsdl:types><wsdl:message name="findIDRequest"><wsdl:part name="parameters" element="ns:findID"/></wsdl:message><wsdl:message name="findIDResponse"><wsdl:part name="parameters" element="ns:findIDResponse"/></wsdl:message><wsdl:portType name="DBAccessPortType"><wsdl:operation name="findID"><wsdl:input message="ns:findIDRequest" wsaw:Action="urn:findID"/><wsdl:output message="ns:findIDResponse" wsaw:Action="urn:findIDResponse"/></wsdl:operation></wsdl:portType><wsdl:binding name="DBAccessSoap11Binding" type="ns:DBAccessPortType"><soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/><wsdl:operation name="findID"><soap:operation soapAction="urn:findID" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation></wsdl:binding><wsdl:binding name="DBAccessSoap12Binding" type="ns:DBAccessPortType"><soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/><wsdl:operation name="findID"><soap12:operation soapAction="urn:findID" style="document"/><wsdl:input><soap12:body use="literal"/></wsdl:input><wsdl:output><soap12:body use="literal"/></wsdl:output></wsdl:operation></wsdl:binding><wsdl:binding name="DBAccessHttpBinding" type="ns:DBAccessPortType"><http:binding verb="POST"/><wsdl:operation name="findID"><http:operation location="findID"/><wsdl:input><mime:content type="text/xml" part="parameters"/></wsdl:input><wsdl:output><mime:content type="text/xml" part="parameters"/></wsdl:output></wsdl:operation></wsdl:binding><wsdl:service name="DBAccess"><wsdl:port name="DBAccessHttpSoap11Endpoint" binding="ns:DBAccessSoap11Binding"><soap:address location="http://localhost:8080/axis2/services/DBAccess.DBAccessHttpSoap11Endpoint/"/></wsdl:port><wsdl:port name="DBAccessHttpSoap12Endpoint" binding="ns:DBAccessSoap12Binding"><soap12:address location="http://localhost:8080/axis2/services/DBAccess.DBAccessHttpSoap12Endpoint/"/></wsdl:port><wsdl:port name="DBAccessHttpEndpoint" binding="ns:DBAccessHttpBinding"><http:address location="http://localhost:8080/axis2/services/DBAccess.DBAccessHttpEndpoint/"/></wsdl:port></wsdl:service></wsdl:definitions>


call.php
<?php

	function objectToArray($d) {
		if (is_object($d)) {
			// Gets the properties of the given object
			// with get_object_vars function
			$d = get_object_vars($d);
		}
 
		if (is_array($d)) {
			/*
			* Return array converted to object
			* Using __FUNCTION__ (Magic constant)
			* for recursive call
			*/
			return array_map(__FUNCTION__, $d);
		}
		else {
			// Return array
			return $d;
		}
	}
   function arrayToObject($d) {
		if (is_array($d)) {
			/*
			* Return array converted to object
			* Using __FUNCTION__ (Magic constant)
			* for recursive call
			*/
			return (object) array_map(__FUNCTION__, $d);
		}
		else {
			// Return object
			return $d;
		}
    }
//getPrice?product=IBM
$client = new SoapClient('http://localhost:8080/axis2/services/DBAccess?wsdl');
/*$para=array('n' => 5);
$result = $client->factorial($para);
*/
$para=array('id'=>'P00121');
$rs = $client->findID($para);
if ($client->fault) {
	echo '<h2>Fault</h2><pre>'; print_r($rs); echo '</pre>';
} else {
	    print_r($rs);;
		 echo "<br/>";
	    $o=objectToArray($rs);
		/* $p=array();
		 foreach($o as $va)
	     {
            foreach($va as $vb)
			    $p=objectToArray($vb);
		 }
		 foreach($p as $value)	 	 	 	
	     {
			 echo "id  =".$value["id"] ."<br/>";
			 echo "title=".$value["title"]. "<br/>";
			 echo "slug=".$value["slug"]. "<br/>";
			 echo "text  =".$value["text"]."<br/>";
			 echo "userid=".$value["userid"]."<br/>";
		 }*/
		//print_r($p);
 }
?>



DBAccess.java

package db.access;
import org.apache.axiom.om.*;
import java.sql.*;
public class DBAccess {
    
	public DBAccess() {
		// TODO Auto-generated constructor stub
	}
	private Connection connectDatabase( )
	{
		Connection con=null;
	  	try
		{
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance(); 
			con = DriverManager.getConnection("jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=D:\\products.mdb");
		}
		catch(Exception e)
		{
		  System.out.println("No connection");
		}

		return con;
	}
	private OMElement createXML(ResultSet rs) throws Exception
	   {
	    ResultSetMetaData rsmd = rs.getMetaData();
		OMFactory  fac = OMAbstractFactory.getOMFactory();
		OMNamespace omNs = fac.createOMNamespace("http://axiom.demo/xsd", "ns");
		OMElement  root =  fac.createOMElement ("Products",omNs);
		
		OMElement element,child;
		while (rs.next())
		{
			element = fac.createOMElement ("Product",omNs);
			child = fac.createOMElement (rsmd.getColumnLabel(1),omNs);
			child.addChild(fac.createOMText(rs.getString(1)));
			element.addChild(child);
			for (int i = 2; i <= rsmd.getColumnCount(); i++)
			{
				child =fac.createOMElement (rsmd.getColumnLabel(i),omNs);
				child.addChild(fac.createOMText(rs.getString(i)));
			    element.addChild(child);
			}
			root.addChild(element);
		}
	   return root;
	 }
    public OMElement findID( String id ) 
    {
	 Connection con=null;
     Statement stmt=null;
     OMElement doc =null;
	  try
	  {
	            con= connectDatabase();
				stmt = (Statement) con.createStatement();
			    ResultSet rs = stmt.executeQuery("SELECT * FROM Products WHERE Pro_id='" + id +"'");
				doc = createXML(rs);
	   }
      catch (Exception e)
	  {
			  e.printStackTrace( );
	  }
	  finally
	  {
			 try
			  {
			      con.close();
			      stmt.close();
			  }
			  catch(SQLException e)
			  {
			    e.printStackTrace( );
			  }
	  }
	 return doc;   
    } 
}






Tag : PHP, Ms Access, WebService







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-03-22 18:02:26 By : TheCatzika View : 1145 Reply : 1
 

 

No. 1



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

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

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

ต่างกันที่ port ของ localhost รึเปล่าครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-03-24 13:10:40 By : mangkunzo
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : มีปัญหาเรื่องการเขียน php เพื่อส่งข้อมูลไปยัง web service ค่ะ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 01
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 อัตราราคา คลิกที่นี่