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