Advertisement

09.25.2007 at 02:40PM PDT, ID: 22852342
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.6

Php5 Soap - Passing arrays via WSDL

Asked by cooperholt in SOAP, PHP Scripting Language

Tags: , , , ,

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/JewelleryService.class.php');
//set up the caching for wsdl
ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache]    

    $server = new SoapServer("http://www.datafodder.net/wshelper15/service.php?class=JewelleryService&wsdl");
    $server->setClass("JewelleryService");
    $server->handle();    
?>

CODE FOR CLASS
<?php
require_once '../conn/conn.php';
require_once("../classes/db/MySQLConnect.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,USERNAME,PASSWORD);
      }
       
/**                            
  *                          
  * 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['sku']);
        $data = $client->getSingleProduct($item);
        //foreach($client->getSingleProduct($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:product[]" />
  </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="getSingleProductRequest">
  <part name="product_id" type="xsd:string" />
  </message>
- <message name="getSingleProductResponse">
  <part name="getSingleProductReturn" type="tns:productArray" />
  </message>
- <wsdl:portType name="JewelleryServicePortType">
- <wsdl:operation name="__construct">
  <wsdl:input message="tns:__constructRequest" />
  </wsdl:operation>
- <wsdl:operation name="getSingleProduct">
  <wsdl:input message="tns:getSingleProductRequest" />
  <wsdl:output message="tns:getSingleProductResponse" />
  </wsdl:operation>
  </wsdl:portType>
- <binding name="JewelleryServiceBinding" type="tns:JewelleryServicePortType">
  <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:JewelleryServiceBinding">
  <soap:address location="http://www.datafodder.net/wshelper15/service.php?class=JewelleryService" />
  </wsdl:port>
  </wsdl:service>
  </wsdl:definitions>Start Free Trial
 
 
[+][-]09.26.2007 at 12:38AM PDT, ID: 19961206

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.26.2007 at 02:51AM PDT, ID: 19961667

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.27.2007 at 02:17AM PDT, ID: 19969735

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: SOAP, PHP Scripting Language
Tags: soap, php, php5, wsdl, array
Sign Up Now!
Solution Provided By: deresh
Participating Experts: 1
Solution Grade: B
 
 
[+][-]09.27.2007 at 03:01AM PDT, ID: 19969893

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628