1

I have created follwing Web Service using Zend Version 1.11

I want to change Namespace where xsd is default change to s. How to change any of the namespace alias?

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

to

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

How can I change Default Message section: Default it is generated as getGroupIn should be getGroupRequest And getGroupOut should be getGroupResponse

Is it possible to change the WSDL Order as per W3C?

The structure of your WSDL is

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

But should be

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;
    }
}

My WSDL Looks like following:

<?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>
Ashwin Parmar
  • 3,025
  • 3
  • 26
  • 42

1 Answers1

1

The namespace is hard-coded in the Zend_Soap_Wsdl class. My recommendation would be to write your own class that extends Zend_Soap_Wsdl and replace the constructor with your own. This would definitely solve the first part of your question.

As for the other aspects of WSDL generation, I think you'll need to step through Zend_Soap_Wsdl, which does the actual generation and figure out which bits need to change in order to produce the WSDL the way you want it. When you figure out which bit of code needs changing, re-write that method in your sub-class and then use your subclass for WSDL generation instead of Zend_Soap_Wsdl.

To use your own class for WSDL generation you will need to pass the class name as the third parameter to the Zend_Soap_AutoDiscover constructor. Your class will also need to be locatable by the auto-loader.

JamesG
  • 4,288
  • 2
  • 31
  • 36
  • One more thing i want to know that is that problem with older version or Zend or it is resolved in Newer version of Zend? I am using Zend Ver. 1.11 – Ashwin Parmar Feb 26 '14 at 04:45
  • I don't use ZF2 but I just had a look at the WSDL class on github and although the code is better in terms of separating the hard-coded stuff out of the methods and into constants, I think you would still need to create your own sub-class to change things like namespace prefixes, etc. So I think you could end up with a cleaner solution, but I don't think it would be any less effort. https://github.com/zendframework/zf2/blob/master/library/Zend/Soap/Wsdl.php – JamesG Feb 26 '14 at 06:32