2011-09-27 62 views
5

你好,我需要写一个SOAP服务器,在那里我将能够通过复杂的类型,structuraly那应该是这样的:如何在ZEND SOAP AutoDiscovery中设置这些复杂类型?

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

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

和I /使用下面的代码来生成这个服务

WSDL文件米
<?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(); 
} 

?> 
在客户端

我得到一个错误:

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 

心中已经尝试了不同的策略,Zend_Soap_Wsdl_Strategy,你可能会看到从包括在我的服务器文件的顶部,但没有成功 我知道,可能我错过了一些东西,但我不知道在哪里看...

我会很高兴,如果有人会能点我到正确的方向,有关这些复杂数据类型的自动发现,至少,如果没有正确的答案,这个问题

因为我不可能得到这个

任何良好的信息预先感谢您

回答

1

我可能不在这里,但我只是使用NuSOAP在PHP中编写了一个Web服务,它允许您可以定义复杂类型并为您生成WSDL。

可能是一个检查出:http://www.scottnichol.com/nusoapintro.htm

在的NuSOAP,创建一个复杂类型像你所提供的一个,该代码会是这个样子:

$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") 
    ) 
);