'PHP SOAP insert data StructType wsdltophp

I am working in a project where I must call SOAP WS. I used WSDLtoPHP, that's really helpful.

I can READ data, and now I would like to create new item with the web services. But when I tried to insert data in the field Nom, I have an error, because the soap server thinks I am trying to insert my data ($nom) inside the attribute NomVide of the field Nom, of the generated xml structure with my code:

<ven1:Nom NomVide="$nom"></ven1:Nom> 

    $createClient = $SC->S001_Creation_Client(new \StructType\S001_Creation_Client(
        new \StructType\RootWSReturnError(
            new \StructType\Header("","","","","",array(),"","","","","","","","","","","",array(),"",0,0,"",array(),array(),"","","","","","","","","","","","","","","","","","","","",0,0,"","",array(),"","","","",0,0,0,0,0,0,0),null),
        new \StructType\RootWSVenteParametres (array( new \StructType\Vente (array("secret_key")))),
        new \StructType\RootWSVenteClient(
            array(new \StructType\Client(
                    new \StructType\General(
                        "3333",
                        array(),
                        array(),
                        null,
                        new \StructType\Nom ($nom),
                        new \StructType\NomRecherche ($nomrecherche),
                        new \StructType\Nom2 ($nom2),
                        new \StructType\Marque1($marque1),
                        new \StructType\Marque2 ($marque2),
                        new \StructType\Adresse1 (),
                        new \StructType\Adresse2 (),
                        new \StructType\CodePostal(),
                        new \StructType\Ville (),
                        new \StructType\County (),
                        new \StructType\CountryRegion (),
                        new \StructType\CurrencyCode ($currencyCode),
                        new \StructType\CreditLimit ($creditLimit),
                        new \StructType\Blocked ($blocked),
                        new \StructType\PaymentMethodCode ($paymentMethodCode),
                        new \StructType\CustDiscGroup ($custDiscGroup),
                        new \StructType\SalespersonCode ($salespersonCode),
                        new \StructType\EquipeAgentCode ($equipeAgentCode),
                        new \StructType\LocationCode($locationCode),[...]

Logs of the SOAP server gave to me then I am trying to do this:

<ven1:Nom NomVide="$nom"></ven1:Nom>

And it is false of course...

BUT I NEED :

<ven1:Nom NomVide="">$nom</ven1:Nom>

Here is my StructType\Nom class code:

    class Nom extends AbstractStructBase
    {
        /**
         * The NomVide
         * Meta information extracted from the WSDL
         * - use: optional
         * @var string|null
         */
        protected ?string $NomVide = null;
        /**
         * Constructor method for Nom
         * @uses Nom::setNomVide()
         * @param string $nomVide
         */
        public function __construct(?string $nomVide = null)
        {
            $this
                ->setNomVide($nomVide);
        }
        /**
         * Get NomVide value
         * @return string|null
         */
        public function getNomVide(): ?string
        {
            return $this->NomVide;
        }
        /**
         * Set NomVide value
         * @param string $nomVide
         * @return \StructType\Nom
         */
        public function setNomVide(?string $nomVide = null): self
        {
            // validation for constraint: string
            if (!is_null($nomVide) && !is_string($nomVide)) {
                throw new InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($nomVide, true), gettype($nomVide)), __LINE__);
            }
            $this->NomVide = $nomVide;
            
            return $this;
        }
    }

Per example there is no problem with the value "3333", which is just a simple string type. I have this problem with all StructType type.

If someone knows how to help me



Solution 1:[1]

I have finally found the solution.

In the WSDL source, there were multiple node with the same name, and in my code only one class were generated by name with WSDLtoPHP.

We asked WSDL owner to change the name of node in the WSDL and we generated new class with WSDLtoPHP librairy.

Now it is work !

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Marc Piatkowski