I'm putting together a SOAP web service using PHP's SoapServer class with a WSDL supplied by a third party. The app runs on Drupal, but this is a separate file that bootstraps Drupal's functions.
The app is on our internal network so I put the WSDL on Pastebin.
This is the code that's producing the anomaly:
$r_userprods = db_query($q_userprods,array(':fid'=>$fid)); $products = array(); // Loop thru their authorized products foreach($r_userprods as $prod) { // Push the product onto the array of products that this teacher has access to $product = new CogneroProduct; $product->CogneroProductID = $prod->casid; $product->DateAuthorizedEpochUTC = $prod->sdate; $product->ProductTitle = $prod->pname; $products[] = $product; } $Instructor->ArrayOfClassitem = $classes; $Instructor->ArrayOfCogneroProductsAuthorized = $products; This is producing the following XML when the service is called:
<ArrayOfCogneroProductsAuthorized> <CogneroProductID>(prod id here)</CogneroProductID> <ProductTitle>(prod name here)</ProductTitle> <DateAuthorizedEpochUTC>(date here)</DateAuthorizedEpochUTC> </ArrayOfCogneroProductsAuthorized> <ArrayOfCogneroProductsAuthorized> <CogneroProductID>(prod id here)</CogneroProductID> <ProductTitle>(prod name here)</ProductTitle> <DateAuthorizedEpochUTC>(date here)</DateAuthorizedEpochUTC> </ArrayOfCogneroProductsAuthorized> <ArrayOfCogneroProductsAuthorized> <CogneroProductID>(prod id here)</CogneroProductID> <ProductTitle>(prod name here)</ProductTitle> <DateAuthorizedEpochUTC>(date here)</DateAuthorizedEpochUTC> </ArrayOfCogneroProductsAuthorized> ... It's actually supposed to be like this:
<ArrayOfCogneroProductsAuthorized> <item> <CogneroProductID>(prod id here)</CogneroProductID> <ProductTitle>(prod name here)</ProductTitle> <DateAuthorizedEpochUTC>(date here)</DateAuthorizedEpochUTC> </item> <item> <CogneroProductID>(prod id here)</CogneroProductID> <ProductTitle>(prod name here)</ProductTitle> <DateAuthorizedEpochUTC>(date here)</DateAuthorizedEpochUTC> </item> <item> <CogneroProductID>(prod id here)</CogneroProductID> <ProductTitle>(prod name here)</ProductTitle> <DateAuthorizedEpochUTC>(date here)</DateAuthorizedEpochUTC> </item> ... </ArrayOfCogneroProductsAuthorized> The ArrayOfCogneroProductAuthorized class has a single property called item, and I'm assigning the variable $products to that property, as I intend there to be one <ArrayOfCogneroProductsAuthorized> in the XML per the correct format above, but it's turning the one property into many copies of that tag.
How can I change the SoapServer code to make the XML match what is expected?
Thank you in advance for any assistance or guidance you can provide.
No comments:
Post a Comment