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!

Php5 Soap - Passing arrays via WSDL

Tags: soap, php, php5, wsdl, array
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 your free trial to view this solution
Question Stats
Zone: Web Development
Question Asked By: cooperholt
Solution Provided By: deresh
Participating Experts: 1
Solution Grade: B
Views: 215
Translate:
Loading Advertisement...
09.26.2007 at 12:38AM PDT, ID: 19961206

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.26.2007 at 02:51AM PDT, ID: 19961667

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.27.2007 at 02:17AM PDT, ID: 19969735

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.27.2007 at 03:01AM PDT, ID: 19969893

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
09.26.2007 at 12:38AM PDT, ID: 19961206

Rank: Master

you could try to serailize array before its returned from soap server
and then deserialize this on client, because in wsdl type for your function return is string, and serializing should fix that.


so instead of:

return $prods;

you return this:

return serialize($prods);

and in your client script:

$item = htmlspecialchars($_POST['sku']);
$data = unserialize($client->getSingleProduct($item));
 
09.26.2007 at 02:51AM PDT, ID: 19961667
Hi there.

I tried that but the error that came back was as follows:
--->
Warning: unserialize() expects parameter 1 to be string, array given in /var/www/web4/web/client_2.php on line 26
bool(false)
--->

I think I figured out how to describe this problem/issue better perhaps...

I need to pass (somehow) the result from the function across soap back to a php5 client, currently the wsdl appears to be correct (when testing against xmethods) but I (may be wrong) have determined that the result coming from the request is actually blank... (ie: an empty array is passed.

My confusion arises from the way the soap client appears to think that the resulting array is an object..

I tweaked the wsdl file to correct an error with the last part (to who the server program).

  <?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="" 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="" 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/webserv/server2.php" />
  </wsdl:port>
  </wsdl:service>
  </wsdl:definitions>
 
09.27.2007 at 02:17AM PDT, ID: 19969735

Rank: Master

hm did you do a serialize before returning array from soap server class function getSingleProduct? if you did that it must return a string, not an array

btw. are you sure that database call goes ok? maybe it returns an empty recordset
Accepted Solution
 
09.27.2007 at 03:01AM PDT, ID: 19969893
Hi there
After some furious digging I realised that you were correct - but I had made a fundamental mistake in the wsdl too!

I am accepting your answer with thanks!

Oo
 
 
20080236-EE-VQP-29 / EE_QW_2_20070628