By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,830 Members | 2,271 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,830 IT Pros & Developers. It's quick & easy.

SOAP Call with multiple occurences of an element

P: n/a
Hi,

I'm a little bit stuck trying to send a SOAP request that includes
multiple occurrences of an element.

For the sake of illustration, this is what the relevant portions of
the SOAP request should look like:

<SyncItems>
<UserContext>
<UserID>some id</UserID>
<AuthToken>some token</AuthToken>
</UserContext>
<allItems>
<anItem>
<name>Item One</name>
<type>Rocket parts</type>
</anItem>
<anItem>
<name>Item Two</name>
<type>Bear skins</type>
</anItem>
<allItems>
</SyncItems>
Here is some PHP code that illustrates how I would construct the
parameters for the call, except I'm not sure how I create the
"allItems" element:

<?php

$uc = array('UserID' ='fred', 'AuthToken' ='a48bf35-24525fea-3c43a25');
$i1 = array('name' ='Item One', 'type' ='Rocket parts');
$i2 = array('name' ='Item Two', 'type' ='Bear skins');
// how do I create $theitems so that the $params array created below
// will work?
$params = array('UserContext' =$uc, 'allItems' =$theitems);
$soapclient->SyncItems($params);

?>

I tried the obvious approach:

$item1 = array('anItem' =$i1);
$item2 = array('anItem' =$i2);
$theitems = array($item1, $item2);

But when I do that, the SOAP client call fails so badly I can't even
get trace information back.

I've been googling for others who may have solved this problem, but I
haven't seen anyone with answers.

Any help or suggestions would be much appreciated!

Nick
--
#include<stdio.h /* sigmask (sig.c) 20041028 PUBLIC DOMAIN */
int main(c,v)char *v;{return !c?putchar(* /* cc -o sig sig.c */
v-1)&&main(0,v+1):main(0,"Ojdl!Wbshjti!=ojdlAwbshjt i/psh?\v\1");}
Oct 2 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Nick Vargish skrev:
$soapclient->SyncItems($params);
I can't find any "SyncItems" in the PHP SOAP extension. Are you using
another SOAP library?

And why $soapCLIENT - it looks like the server side code?

Anyway, you might try using the stdClass object
(http://php.net/manual/en/reserved.classes.php) to build your response
structure.

$response = new stdClass();
$response->x = 'x';
$response->y[] = 'y1';
$repsonse->y[] = 'y2';

and so on...

Regards

Jonathan
Oct 3 '08 #2

P: n/a

I found the solution to my problem in this bug report:

http://bugs.php.net/bug.php?id=45284

The solution is that the array of items must have integer keys
starting with 0.

Thanks!

Nick

--
#include<stdio.h /* sigmask (sig.c) 20041028 PUBLIC DOMAIN */
int main(c,v)char *v;{return !c?putchar(* /* cc -o sig sig.c */
v-1)&&main(0,v+1):main(0,"Ojdl!Wbshjti!=ojdlAwbshjt i/psh?\v\1");}
Oct 3 '08 #3

P: n/a
Nick Vargish skrev:
The solution is that the array of items must have integer keys
starting with 0.
This is exactly what your approach with
$theitems = array($item1, $item2);
should give you.

How is your solution now?

Regards

Jonathan
Oct 3 '08 #4

P: n/a
Jonathan Stein <js****@image.dkwrites:
This is exactly what your approach with
$theitems = array($item1, $item2);
should give you.
How is your solution now?
It's working, thanks. Part of the problem is that the element that
contains the array doesn't correspond to any of the names in the WSDL
(I guess it's implied), so I had an extra named parameter in there
that was throwing things off.

It makes sense now, it just took a sort of intuitive leap to grasp it.

Nick

--
#include<stdio.h /* sigmask (sig.c) 20041028 PUBLIC DOMAIN */
int main(c,v)char *v;{return !c?putchar(* /* cc -o sig sig.c */
v-1)&&main(0,v+1):main(0,"Ojdl!Wbshjti!=ojdlAwbshjt i/psh?\v\1");}
Oct 7 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.