您好,我需要编写一个SOAP服务器,在这里我可以传递结构如下的复杂类型:

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

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

和I/m,使用以下代码为该服务生成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策略,您可能会从服务器文件顶部的包含项中看到,但根本没有成功
我知道我可能会丢失一些东西,但是我不确定要看的地方...

如果有人能够针对这些复杂的类型和自动发现向我指出正确的方向,我将很高兴,至少,如果不是正确的答案,我将对此感到满意。

因为我无法获得任何良好的信息

先感谢您

最佳答案

我可能不在这里,但是我只是使用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")
    )
);

10-06 12:42
查看更多