1

我使用 Zend 1.11 版创建了以下 Web 服务

我想将xsd默认更改为的命名空间更改为s. 如何更改任何命名空间别名?

xmlns:xsd="http://www.w3.org/2001/XMLSchema"

xmlns:s="http://www.w3.org/2001/XMLSchema"

如何更改默认消息部分:默认生成getGroupIn应该是getGroupRequest 并且 getGroupOut应该是getGroupResponse

是否可以根据 W3C 更改 WSDL 订单?

您的 WSDL 的结构是

types (1)
portType (1)
binding (1)
service (1)
message (2)

但应该是

types
messages
portTypes
bindings
services

WSDL

if(isset($_GET['wsdl'])) {
    $autodiscover = new Zend_Soap_AutoDiscover('Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex');
    $autodiscover->setUri("http://localhost/ZendSoap/services/testwsdl.php");
    $autodiscover->setClass('Test');
    $autodiscover->handle();
} else {
    $soap = new Zend_Soap_Server("http://localhost/ZendSoap/services/testwsdl.php?wsdl"); // this current file here
    $soap->setClass('Test');
    $soap->handle();
}

class Person
{
    /** @var string */
    public $name = '';
}

class Group
{
    /** @var Person[] */
    public $persons;
}
class Test
{
    /**
     * @return Group
     */
    public function getGroup()
    {
        $group = new Group();

        $person = new Person();
        $person->name = "Annah";
        $group->persons[] = $person;

        $person = new Person();
        $person->name = "Sarah";
        $group->persons[] = $person;

        return $group;
    }
}

我的 WSDL 如下所示:

<?xml version="1.0"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://localhost/ZendSoap/services/testwsdl.php" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="Test" targetNamespace="http://localhost/ZendSoap/services/testwsdl.php">
    <types>
        <xsd:schema targetNamespace="http://localhost/ZendSoap/services/testwsdl.php">
            <xsd:complexType name="ArrayOfPerson">
                <xsd:complexContent>
                    <xsd:restriction base="soap-enc:Array">
                        <xsd:attribute ref="soap-enc:arrayType" wsdl:arrayType="tns:Person[]"/>
                    </xsd:restriction>
                </xsd:complexContent>
            </xsd:complexType>
            <xsd:complexType name="Person">
                <xsd:all>
                    <xsd:element name="name" type="xsd:string"/>
                </xsd:all>
            </xsd:complexType>
            <xsd:complexType name="Group">
                <xsd:all>
                    <xsd:element name="persons" type="tns:ArrayOfPerson" nillable="true"/>
                </xsd:all>
            </xsd:complexType>
        </xsd:schema>
    </types>
    <portType name="TestPort">
        <operation name="getGroup">
            <documentation>@return Group</documentation>
            <input message="tns:getGroupIn"/>
            <output message="tns:getGroupOut"/>
        </operation>
    </portType>
    <binding name="TestBinding" type="tns:TestPort">
        <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
        <operation name="getGroup">
            <soap:operation soapAction="http://localhost/ZendSoap/services/testwsdl.php#getGroup"/>
            <input>
                <soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost/ZendSoap/services/testwsdl.php"/>
            </input>
            <output>
                <soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost/ZendSoap/services/testwsdl.php"/>
            </output>
        </operation>
    </binding>
    <service name="TestService">
        <port name="TestPort" binding="tns:TestBinding">
            <soap:address location="http://localhost/ZendSoap/services/testwsdl.php"/>
        </port>
    </service>
    <message name="getGroupIn"/>
    <message name="getGroupOut">
        <part name="return" type="tns:Group"/>
    </message>
</definitions>
4

1 回答 1

1

命名空间在类中是硬编码的Zend_Soap_Wsdl。我的建议是编写你自己的类,Zend_Soap_Wsdl用你自己的扩展和替换构造函数。这肯定会解决您问题的第一部分。

至于 WSDL 生成的其他方面,我认为您需要逐步完成Zend_Soap_Wsdl实际生成并确定需要更改哪些位才能以您想要的方式生成 WSDL。当您确定需要更改哪部分代码时,请在您的子类中重新编写该方法,然后使用您的子类生成 WSDL 而不是Zend_Soap_Wsdl.

要使用您自己的类来生成 WSDL,您需要将类名作为第三个参数传递给Zend_Soap_AutoDiscover构造函数。你的类也需要被自动加载器定位。

于 2014-02-26T03:51:25.177 回答