Structuring PHP array for use in SOAP with WSDL
I am writing a SoapServer with PHP 5.2 to return a list of vacancies to another application. My WSDL doc requires a complex type along the lines of:
<xsd:element name="Vacancies">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Vacancy" type="ns:VacancyType" minOccurs="0" maxOccurs="unbounded"></xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:elemen开发者_如何学编程t>
My function is generating a large, nested array to assemble each vacancy and then returning the array of arrays (ie: vacancies) to the SoapServer.
Unfortunately, each array is indexed. So each VacancyType element within Vacancies has a unique index. This seems to throw the WSDL definition off and the data returned to me simply throws a parse error. I'd normally use associative arrays for key pair values, but as I'm dealing with n instances of VacancyType that wouldn't work as there wouldn't be a unique reference.
Is there a known workaround for this kind of scenario (eg: maybe an object), or should I rework my WSDL doc to cater for indexed arrays?
Thanks
According to http://sam.xnet.tk/post/15/php-soap-server-part-2/ the rpc/literal style is working with xsd sequence. However, i cannot make it work with document/literal wrapped style, too.
Did you gave nuSAOP a try? Requires no other installed PHP libs:
- http://sourceforge.net/projects/nusoap/
According to PHP documentation, PHP supports subsets of SOAP 1.1, SOAP 1.2 and WSDL 1.1.
After all, I have found a solution: I construct XML by mysefl and use
new SoapVar('<myitem>...</myitem><myitem>...</myitem>', XSD_ANYXML);
精彩评论