Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

classmap option not working while using php's SoapClient

Currently I am working on an internal soap service to control some internal processes. Which is normally not all that hard to do. I am however trying to use the soapClient classmap functionality to map objects instead of working with the stdClasses which are normally returned for non complextypes.

Considering the fact that wsdl's and sources take up alot of space code-wise, i will link to relevant documents instead of spamming them in this question.

First of all I am using Zend_Soap_Server and Zend_Soap_Server_Autodiscover for my Soap service and wsdl generation.

Soap server code: https://www.dropbox.com/s/eji7l50g42m2ixl/SoapServer.txt

WSDL result for ?wsdl request: https://www.dropbox.com/s/vyxbjz7wogd8suy/wsdl.txt

The soap service publishes a serviceclass. This class contains a method to obtain data from our soap service. This method is called getPackages.

getPackages method form the soap service: https://www.dropbox.com/s/p5ddxpraju7ru6x/method_from_serviceclass.txt

The getPackages method returns a DataObject which in turn returns contains references to other data objects. These objects exist on both server as client and are exactly the same on both ends.

The main data object: https://www.dropbox.com/s/qt51pw3rpq7c2ba/dataobject.txt

When connecting to this service and calling the getPackages method, I get the response as expected: a stdClass containing a vps and a shared property.

Unfortionatly when adding the classmap, the result remains exactly the same.. a stdClass containing vps and a shared property. The expected result would be a Soho_Soap_DataObject_Packages object containing the vps and shared properties.

This is the used SoapClient code: https://www.dropbox.com/s/ulnni84p8dawv97/SoapClient.txt

When i call the getPackages method through Soap i get the following:

$SoapClient = \Soho_Soap_Client::getInstance();
$packages = $SoapClient->getPackages();
print_r($packages);

Output:

stdClass Object
(
[shared] => Array
    (
        [0] => stdClass Object
            (
                [id] => 
                [title] => 
                [pricePerPeriod] => 
                [price] => 
                [minRegistrationMonths] => 
                [properties] => 
                [options] => Array
                    (
                    )
            )
    )
[vps] => 

)

However, if I look at the response types I get the following:

print_r( $SoapClient->__getTypes() );

Output:

    Array
    (
    [0] => Soho_Soap_DataObject_Package_Shared ArrayOfSoho_Soap_DataObject_Package_Shared[]
    [1] => struct stdClass {

    }
    [2] => Soho_Soap_DataObject_Package_Shared_Option ArrayOfSoho_Soap_DataObject_Package_Shared_Option[]
    [3] => struct Soho_Soap_DataObject_Package_Shared_Option {
        string title;
        string value;
    }
    [4] => struct Soho_Soap_DataObject_Package_Shared {
        int id;
        string title;
        int pricePerPeriod;
        int price;
        int minRegistrationMonths;
        stdClass properties;
        ArrayOfSoho_Soap_DataObject_Package_Shared_Option options;
    }
    [5] => Soho_Soap_DataObject_Package_Vps ArrayOfSoho_Soap_DataObject_Package_Vps[]
    [6] => Soho_Soap_DataObject_Package_Vps_Option ArrayOfSoho_Soap_DataObject_Package_Vps_Option[]
    [7] => struct Soho_Soap_DataObject_Package_Vps_Option {
        string title;
        string value;
    }
    [8] => struct Soho_Soap_DataObject_Package_Vps {
        int id;
        string title;
        int pricePerPeriod;
        int price;
        int minRegistrationMonths;
        stdClass properties;
        ArrayOfSoho_Soap_DataObject_Package_Vps_Option options;
    }
    [9] => struct Soho_Soap_DataObject_Packages {
        ArrayOfSoho_Soap_DataObject_Package_Shared shared;
        ArrayOfSoho_Soap_DataObject_Package_Vps vps;
    }
    )        

Google isn't helping me much since the classmapping documentiation isn't all too great to start with, so I hope the stack community can shine a light on my problem.

2 days of staring at the same problem makes me desperate.

A short while ago I used SoapClient in the same way to communicate with a vmware vsphere API which worked perfectly, so I do think the problem has something to do with the WDSL, but currently I am lost.

I thank everyone that takes the time to look at my problem in advance for their time. I will ofcourse provide additional information when requested.

like image 572
Damien Overeem Avatar asked Nov 07 '12 09:11

Damien Overeem


1 Answers

One thing jumps out when looking at the code, and that is that the zend_soap_server instance should use it's own WSDL, like this:

$SoapServer = new Zend_Soap_Server($urltowsdl, array('classmap' => $classmap));
like image 70
Johannes Konst Avatar answered Oct 15 '22 22:10

Johannes Konst