1

我目前正在使用 Zend_Soap_AutoDiscover 生成我的 WSDL 文件,问题是我希望这个 wsdl 处理类型为 ArrayOfString ( string[] ) 的输出。所以我将复杂类型策略更改为 Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence,它可以正常工作,但问题是输出并不是真正的字符串数组,输出 xml 是这样的:

<xsd:complexType name="ArrayOfString">
    <xsd:sequence>
        <xsd:element name="item" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
    </xsd:sequence>
</xsd:complexType>

但我想要这样的输出:

<xsd:complexType name="ArrayOfstring">
    <xsd:complexContent>
        <xsd:restriction base="soapenc:Array">
            <xsd:attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:string[]"/>
        </xsd:restriction>
    </xsd:complexContent>
</xsd:complexType>

所以,我使用了新策略 Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex,但问题是这个策略不处理 string[]。

最后->我该怎么办:D?!

4

1 回答 1

2

Try creating a response class that has just one attribute, as follows:

class Response
{
    /** @var string[] */
    public $items;
}

Then define your service class to return an object of type Response, as follows:

class Service
{
    /**
     * @param string
     * @return Response
     */
    public function process( $input )
    {
        $response = new Response();
        // Populate $response->items[] object with strings...
        return $response;
    }
}

Then use the 'Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex' strategy when using Zend_Soap_Autodiscover to create the WSDL. Although this probably won't produce precisely the output you're after, it should produce something that is semantically closer than what you're currently getting. The key with this approach is to get the PHPDoc right.

If that still doesn't work, post the key bits of your code, as that will help resolve the issue more quickly.

于 2010-03-19T12:15:20.267 回答