Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set these complex types in ZEND SOAP AutoDiscovery?

Hello I need to write a SOAP server, where I would be able to pass complex types, structuraly that would look like this:

<ParcelDetails>
  <countryType></countryType>
  <addressType>
    <countryType></countryType>
      .... .....
      .... ....

    <contact></contact>
  </addressType>
<ParcelDetails>

and I/m using following code to generate WSDL file for this service

<?php
include_once("Zend/Soap/Wsdl/Strategy/ArrayOfTypeSequence.php");
include_once("Zend/Soap/Wsdl/Strategy/DefaultComplexType.php");
include_once("Zend/Soap/Wsdl/Strategy/Composite.php");
include_once("Zend/Soap/Wsdl/Strategy/ArrayOfTypeComplex.php");
include_once("Zend/Soap/Wsdl/Strategy/AnyType.php");
include_once('Zend/Soap/AutoDiscover.php');

include_once('Zend/Soap/Server.php');
include_once('Zend/Soap/Client.php');
include_once('Zend/Soap/Wsdl.php');

//*************************************
// Classes used by getGroup service method below 

class countryTypeSpace
{
    /** @var country */
    public $country = '';
}

class addressTypeSpace
{
    /** @var countryType */
    public $countryType = '';

    ....

    /** @var contact */
    public $contact = '';

}



class ParcelDetailsSpace
{

    /** @var countryType */
    public $countryType;

    /** @var addressType[]  */
    public $addressType;

}

//*************************************

class ServiceClass  
{
    /**
     *  ParcelDetails
     */
    public function registerParcel( $username, $pasword) {

        $group = new ParcelDetailsSpace();

        //fill in the array
        for ($i = 1; $i <= 3; $i++) {
            $countryType = new countryType();
            $countryType->country = 'country';

            $addressType = new addressTypeSpace();
            $addressType->address = 'Adresas';
            $addressType->area = 'Area';


            $group->countryType = $countryType;
            $group->addressType = $addressType;
        }

        return $group;
    }       
}


if(isset($_GET['wsdl'])) {
    $autodiscover = new Zend_Soap_AutoDiscover('Zend_Soap_Wsdl_Strategy_AnyType');
    $autodiscover->setClass('ServiceClass');
    $autodiscover->handle();
} else {
    $soap = new Zend_Soap_Server("http://localhost/zs/zserverComplex.php?wsdl");
    $soap->setClass('ServiceClass');
    $soap->handle();
}

?>

on the client end I'm getting an error:

 Fatal error: Uncaught SoapFault exception: [VersionMismatch] Wrong
 Version in C:\Program Files
 (x86)\EasyPHP-5.3.8.0\www\zs\Zend\Soap\Client.php:1121 Stack trace:

# 0 C:\Program Files
 (x86)\EasyPHP-5.3.8.0\www\zs\Zend\Soap\Client.php(1121):
 SoapClient->__soapCall('registerParcel', Array, NULL, NULL, Array) 

# 1 C:\Program Files (x86)\EasyPHP-5.3.8.0\www\zs\zclientDpd.php(6):
 Zend_Soap_Client->__call('registerParcel', Array) 

#2 C:\Program Files
 (x86)\EasyPHP-5.3.8.0\www\zs\zclientDpd.php(6):
 Zend_Soap_Client->registerParcel(Array) 

#3 {main} thrown in C:\Program Files
(x86)\EasyPHP-5.3.8.0\www\zs\Zend\Soap\Client.php on line 1121

I'v tried different Zend_Soap_Wsdl_Strategy strategies as you might see from includes at the top of my server file, but no success at all I know that probably I'm missing something, but I'm not sure where to look...

I would be glad if someone would be able to point me to the right direction, about these complex types and auto discovery, at least, if not the right answer to this problem

Because I couldnt get any good info on this

Thank you in advance

like image 659
madcatzx Avatar asked Nov 14 '22 16:11

madcatzx


1 Answers

I might be out of my league here, but I just wrote a web service in PHP using NuSOAP, and it allows you to define complex types and generates the WSDL for you.

Might be something to check out: http://www.scottnichol.com/nusoapintro.htm

In NuSOAP, to create a complex type like the one you provided, the code would look something like this:

$server = new nusoap_server();

$server->wsdl->addComplexType(
    "addressType",
    "complexType",
    "struct",
    "all",
    "",
    array(
        "countryType" => array("name" => "countryType", "type" => "xsd:string"),
        ...
        "contact" => array("name" => "contact", "type" => "xsd:string")
    )
);

$server->wsdl->addComplexType(
    "ParcelDetails",
    "complexType",
    "struct",
    "all",
    "",
    array(
        "countryType" => array("name" => "countryType", "type" => "xsd:string"),
        "addressType" => array("name" => "addressType", "type" => "tns:addressType")
    )
);
like image 141
Travesty3 Avatar answered Mar 07 '23 02:03

Travesty3