I have a wsdl file which describes a service written in php5 - currently the resultant array provided by the soap server to a php5 soap client winds up as a empty stdClass rather than an array. I have written a class (with one method only) which is supposed to return a simple array.
Flash sees the web service and appears to validate it, however as its expecting an array no data results from the call using web services in flash either.
When testing the class on the server the class returns an array correctly so I know the function works.
What I need to establish is if the wsdl file is correctly describing the service, the wsdl was generated by a creator class (
www.jool.nl/webservicehelper/).
I show the code below along with the wsdl file.
CODE (server)
<?php
//require the various classes that we use
require_once '../conn/conn.php';
require_once('../classes/J
ewellerySe
rvice.clas
s.php');
//set up the caching for wsdl
ini_set("soap.wsdl_cache_e
nabled", "0"); // disabling WSDL cache]
$server = new SoapServer("
http://www.datafodder.net/wshelper15/service.php?class=JewelleryService&wsdl");
$server->setClass("Jewelle
ryService"
);
$server->handle();
?>
CODE FOR CLASS
<?php
require_once '../conn/conn.php';
require_once("../classes/d
b/MySQLCon
nect.php")
;
/**
*
* This webservice provides access to the Jewellery range data
* and allows searching and other functions
*/
class JewelleryService {
/**
*
* @return void
*/
function __construct() {
//public function to set up class
$this->db = MySQLConnect::getInstance(
HOST,USERN
AME,PASSWO
RD);
}
/**
*
* This method returns a single product inside an array.
* @param string product_id
* @return product[]
*/
public function getSingleProduct($product_
id) {
if ($product_id != "") {
$query = sprintf("SELECT * FROM products_prd WHERE sku_prd = '%s'",$product_id);
$data = $this->db->createResultSet
($query, DATABASE);
//pull the data from the db
foreach($data as $row ){
$prods = array();
$prods['product_id'] = $row['id_prd'];
$prods['name'] = $row['name_prd'];
$prods['price'] = $row['price_prd'];
$prods['stocklevel'] = $row['stocklevel_prd'];
$prods['description'] = $row['description_prd'];
$prods['category'] = $row['category_prd'];
$prods['rsize'] = $row['ring_size'];
}
return $prods;
} else {
throw new SoapFault("Server","No Request Made '$product_id'.");
}
}
}
?>
CODE FOR CLIENT
<<Part shown that does the work>>
$client = new SoapClient("
http://www.datafodder.net/wshelper15/service.php?class=JewelleryService&wsdl");
try {
$item = htmlspecialchars($_POST['s
ku']);
$data = $client->getSingleProduct(
$item);
//foreach($client->getSing
leProduct(
$item) as $key => $value){
var_dump($data);
echo($data->name);
//($key." = ".$value."<br>"); this was supposed to echo an array
//}
} catch (SoapFault $exception) {
echo $exception;
}
FINALLY THE WSDL COPIED FORM THE WEB PAGE
<?xml version="1.0" ?>
- <wsdl:definitions xmlns="
http://schemas.xmlsoap.org/wsdl/" xmlns:soap="
http://schemas.xmlsoap.org/wsdl/soap/" xmlns:SOAP-ENC="
http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="
http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="
http://www.w3.org/2001/XMLSchema" xmlns:tns="
http://schema.example.com" targetNamespace="
http://schema.example.com">
+ <wsdl:types>
- <xsd:schema targetNamespace="
http://schema.example.com">
- <xsd:complexType name="productArray">
- <xsd:complexContent>
- <xsd:restriction base="SOAP-ENC:Array">
<xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="tns:produc
t[]" />
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
- <xsd:complexType name="product">
- <xsd:all>
<xsd:element name="category" type="xsd:string" />
<xsd:element name="description" type="xsd:string" />
<xsd:element name="name" type="xsd:string" />
<xsd:element name="price" type="xsd:float" />
<xsd:element name="product_id" type="xsd:int" />
<xsd:element name="rsize" type="xsd:string" />
<xsd:element name="stocklevel" type="xsd:int" />
</xsd:all>
</xsd:complexType>
</xsd:schema>
</wsdl:types>
<message name="__constructRequest" />
- <message name="getSingleProductRequ
est">
<part name="product_id" type="xsd:string" />
</message>
- <message name="getSingleProductResp
onse">
<part name="getSingleProductRetu
rn" type="tns:productArray" />
</message>
- <wsdl:portType name="JewelleryServicePort
Type">
- <wsdl:operation name="__construct">
<wsdl:input message="tns:__constructRe
quest" />
</wsdl:operation>
- <wsdl:operation name="getSingleProduct">
<wsdl:input message="tns:getSingleProd
uctRequest
" />
<wsdl:output message="tns:getSingleProd
uctRespons
e" />
</wsdl:operation>
</wsdl:portType>
- <binding name="JewelleryServiceBind
ing" type="tns:JewelleryService
PortType">
<soap:binding style="rpc" transport="
http://schemas.xmlsoap.org/soap/http" />
- <wsdl:operation name="__construct">
<soap:operation soapAction="
http://www.datafodder.net/wshelper15/service.php?class=JewelleryService&method=__construct" style="rpc" />
- <wsdl:input>
<soap:body use="encoded" namespace="
http://schema.example.com" encodingStyle="
http://schemas.xmlsoap.org/soap/encoding/" />
</wsdl:input>
</wsdl:operation>
- <wsdl:operation name="getSingleProduct">
<soap:operation soapAction="
http://www.datafodder.net/wshelper15/service.php?class=JewelleryService&method=getSingleProduct" style="rpc" />
- <wsdl:input>
<soap:body use="encoded" namespace="
http://schema.example.com" encodingStyle="
http://schemas.xmlsoap.org/soap/encoding/" />
</wsdl:input>
- <wsdl:output>
<soap:body use="encoded" namespace="
http://schema.example.com" encodingStyle="
http://schemas.xmlsoap.org/soap/encoding/" />
</wsdl:output>
</wsdl:operation>
</binding>
- <wsdl:service name="JewelleryService">
- <wsdl:port name="JewelleryServicePort
" binding="tns:JewelleryServ
iceBinding
">
<soap:address location="
http://www.datafodder.net/wshelper15/service.php?class=JewelleryService" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Start Free Trial