Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating complex type of an array of basic data types #2

Open
Schaumbaum opened this issue Nov 30, 2014 · 6 comments
Open

Creating complex type of an array of basic data types #2

Schaumbaum opened this issue Nov 30, 2014 · 6 comments

Comments

@Schaumbaum
Copy link

Hi Dragos,

sorry for opening a new issue, but I don't found your contact email, otherwise I had contacted you directly. First, thanks for your fast support. Unfortunately your changes don't work for my scenario.
Now arrays of basic data types are not resulting in complex types anymore, as they are handled as basic array.

<message name="testMethodIn">
    <part name="para1" type="soap-enc:Array"/>
    <part name="para2" type="soap-enc:Array"/>
</message>
<message name="testMethodOut">
    <part name="return" type="soap-enc:Array"/>
</message>

That's ok for php and his dynamic typing, but are more strict languages would like to know what data type is stored within the array.

My corresponding method for this example:

     /**
     * @param string[] $para1
     * @param bool[] $para2
     * @return string[]
     */
    public function testMethod($para1, $para2){
        return array("ret1","ret2");
    }

I think the resulting wsdl parts It should look something like that:

  1. the data definition
<xsd:complexType name="ArrayOfString">
    <xsd:complexContent>
        <xsd:restriction base="soap-enc:Array">
            <xsd:attribute ref="soap-enc:arrayType" wsdl:arrayType="xsd:string[]"/>
        </xsd:restriction>
    </xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="ArrayOfBool">
    <xsd:complexContent>
        <xsd:restriction base="soap-enc:Array">
            <xsd:attribute ref="soap-enc:arrayType" wsdl:arrayType="xsd:bool[]"/>
        </xsd:restriction>
    </xsd:complexContent>
</xsd:complexType>
  1. the message definitions
<message name="testMethodIn">
    <part name="para1" type="tns:ArrayOfString"/>
    <part name="para2" type="tns:ArrayOfBool"/>
</message>
<message name="testMethodOut">
    <part name="return" type="tns:ArrayOfString"/>
</message>

I have changed the addComplexTypeArray method to achieve this.

protected function addComplexTypeArray($singularType, $type)
    {
        $isBasicDataType = isset(self::$XSDTypes[strtolower($singularType)]);
        $nsPrefix = $isBasicDataType ? 'xsd' : 'tns';

        $xsdComplexTypeName = 'ArrayOf' . ucfirst(static::typeToQName($singularType));
        $xsdComplexType = 'tns:' . $xsdComplexTypeName;

        // Register type here to avoid recursion.
        $this->addType($type, $xsdComplexType);

        // Process singular type using DefaultComplexType strategy.
        if(!$isBasicDataType){
            $this->addComplexType($singularType);
        }

        // Add array type structure to WSDL document.
        $complexType = $this->dom->createElement('xsd:complexType');
        $complexType->setAttribute('name', $xsdComplexTypeName);

        $complexContent = $this->dom->createElement('xsd:complexContent');
        $complexType->appendChild($complexContent);

        $xsdRestriction = $this->dom->createElement('xsd:restriction');
        $xsdRestriction->setAttribute('base', 'soap-enc:Array');
        $complexContent->appendChild($xsdRestriction);

        $xsdAttribute = $this->dom->createElement('xsd:attribute');
        $xsdAttribute->setAttribute('ref', 'soap-enc:arrayType');
        $xsdAttribute->setAttribute('wsdl:arrayType', $nsPrefix.':' . static::typeToQName($singularType) . '[]');
        $xsdRestriction->appendChild($xsdAttribute);

        $this->schema->appendChild($complexType);

        return $xsdComplexType;
    }

Hopefully it also works as desired with objects.
If you have any example for an object, that is not working properly with this changes feel free to inform me.

@dragosprotung
Copy link
Owner

Hi,

you are right, array of scalars will be described as basic data types.

Can you can modify the code, change the tests as a pull request ?

@Schaumbaum
Copy link
Author

Sure, I hope to get the time this week.

@dragosprotung
Copy link
Owner

@Schaumbaum Any progress ?

@mstrey
Copy link

mstrey commented Jun 30, 2020

Sure, I hope to get the time this week.
@Schaumbaum any progress? Do you have a branch with anything you do?

@ekrellw
Copy link

ekrellw commented Nov 13, 2021

is this issue solved? I am trying to find out if array and complex types work.

@ekrellw
Copy link

ekrellw commented Nov 24, 2021

I am willing to take whatever has been written and finish it in order to have support of complex types and arrays and optional fields (like minOccurs="0" maxOccurs="1")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants