|
 |
|
มีปัญหาเรื่องการเขียน php เพื่อส่งข้อมูลไปยัง web service ค่ะ |
|
 |
|
|
 |
 |
|
ได้ทำการส้ราง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

|
|
 |
 |
 |
 |
Date :
2012-03-22 18:02:26 |
By :
TheCatzika |
View :
1192 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ต่างกันที่ port ของ localhost รึเปล่าครับ
|
 |
 |
 |
 |
Date :
2012-03-24 13:10:40 |
By :
mangkunzo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|