Giganews Newsgroups

SOAP Call with multiple occurences of an element

This is a discussion on SOAP Call with multiple occurences of an element within the PHP Language forums, part of the PHP Programming Forums category; Hi, I'm a little bit stuck trying to send a SOAP request that includes multiple occurrences of an element. ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-02-2008
Nick Vargish
 
Posts: n/a
Default SOAP Call with multiple occurences of an element

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");}
Reply With Quote
  #2 (permalink)  
Old 10-03-2008
Jonathan Stein
 
Posts: n/a
Default Re: SOAP Call with multiple occurences of an element

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
Reply With Quote
  #3 (permalink)  
Old 10-03-2008
Nick Vargish
 
Posts: n/a
Default Re: SOAP Call with multiple occurences of an element


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");}
Reply With Quote
  #4 (permalink)  
Old 10-03-2008
Jonathan Stein
 
Posts: n/a
Default Re: SOAP Call with multiple occurences of an element

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
Reply With Quote
  #5 (permalink)  
Old 10-07-2008
Nick Vargish
 
Posts: n/a
Default Re: SOAP Call with multiple occurences of an element

Jonathan Stein <jstein@image.dk> writes:

> 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");}
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 01:17 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0