I have fallen into a PHP hole that I can't seem to google myself out of. I have a PHP soap server where one function takes an array of int as input. How do I parse it properly?
When the input is one int, it works. When it is an array, it parses the string 'Array'.
The server is run on my Synology NAS. I've been trying to find some kind of PHP log where the soap server could scream its potential parsing problems, but I have not found any such log.
This is my simplified server:
<?php
if(!extension_loaded("soap")){
dl("php_soap.dll");
}
ini_set("soap.wsdl_cache_enabled","0");
$server = new SoapServer("input_array_debug.wsdl");
function createProduct($content_refs){
$debugVar = "outside";
foreach ($content_refs as $reference) {
$debugVar = "inside";
error_log("Item:'".$reference."'
", 3, "/var/tmp/my-errors.log");
$debugVar = "after";
}
return $debugVar;
}
$server->AddFunction("createProduct");
$server->handle();
This is my WSDL:
<?xml version="1.0"?>
<definitions
name="FoodContent"
targetNamespace="urn:FoodContent"
xmlns:tns="urn:FoodContent"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:FoodContent">
<xsd:complexType name="ArrayOfInt">
<xsd:sequence>
<xsd:element minOccurs="1" maxOccurs="unbounded" name="reference" type="xsd:int" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</types>
<message name="createProduct">
<part name="content_refs" type="tns:ArrayOfInt" />
</message>
<message name="createProductResponse">
<part name="reference" type="xsd:string" />
</message>
<portType name="FoodContentPort">
<operation name="createProduct">
<input message="tns:createProduct" />
<output message="tns:createProductResponse" />
</operation>
</portType>
<binding name="FoodContentBinding" type="tns:FoodContentPort">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="createProduct">
<soap:operation soapAction="urn:FoodContentAction" />
<input>
<soap:body use="encoded" namespace="urn:FoodContent" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body use="encoded" namespace="urn:FoodContent" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
</binding>
<service name="FoodContentService">
<port name="FoodContentPort" binding="tns:FoodContentBinding">
<soap:address location="http://other.eu:8888/FoodContents/Debug_server.php" />
</port>
</service>
</definitions>
The base of the soap request is generated and sent from soapUI 4.0.1:
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:FoodContent">
<soapenv:Header/>
<soapenv:Body>
<urn:createProduct soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<content_refs xsi:type="urn:ArrayOfInt">
<!--1 or more repetitions:-->
<reference xsi:type="xsd:int">3</reference>
<reference xsi:type="xsd:int">7</reference>
</content_refs>
</urn:createProduct>
</soapenv:Body>
</soapenv:Envelope>
The response looks OK