[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How do I send in a multi-line request in nuSoap

Posted on 2009-05-08
6
Medium Priority
?
379 Views
Last Modified: 2013-12-13
We have a web-service that we will use for accepting orders from our customer. An extranet.
The service expects a ><SOAP-ENV:Body> as
<InsertOrder>
<order>
<CustomerCode>14593</CustomerCode>
<OrderLines>
<OrderLine>
<OrderedQuantity>3000</OrderedQuantity>
<ProductCode>141707</ProductCode>
</OrderLine>
</OrderLines>
</order>
</InsertOrder>

This I can do with a structure like

$nyorder = array('CustomerCode' => '14593',
                        'OrderLines' => array
                              ('OrderLine' => array
                                    ('ProductCode'=> '141707','OrderedQuantity' => '3000')
                              )
                        );
and

$result = $proxy->InsertOrder(array('order' => $nyorder));

Problem is I need tobe able to send in multiple <OrderLine> as one request.
But I can not figure out how to create this parameter as I can't create a normal associative array with multiple 'OrderLine' => array(.....
as they will all (of course) have the same key and I will only see the last one I create.

Or maybe I'm going at it from a complete wrong angle (SOAP newbie)

I hope any of this makes sense and I also hope the solution is obvious once I see it. (It usually is)

r

Mats Andersson

This is a XML I would need to create from an array.
 
<InsertOrder>
<order>
<CustomerCode>14593</CustomerCode>
<OrderLines>
<OrderLine>
<OrderedQuantity>3000</OrderedQuantity>
<ProductCode>141707</ProductCode>
</OrderLine>
<OrderLine>
<OrderedQuantity>1000</OrderedQuantity>
<ProductCode>341432</ProductCode>
</OrderLine>
</OrderLines>
</order>
</InsertOrder>

Open in new window

0
Comment
Question by:ShimodaFI
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24340286
Wrap an extra array around your OrderLine items:
$nyorder = array(
  'CustomerCode' => '14593', 
  'OrderLines' => array(
    array('OrderLine' => array('ProductCode'=> '141707','OrderedQuantity' => '3000')),
    array('OrderLine' => array('ProductCode'=> '341432','OrderedQuantity' => '1000'))
  )
);

Open in new window

0
 

Author Comment

by:ShimodaFI
ID: 24342612
No, I have tried that and it does not work as the second array 'OrderLine' will have the same key ('OrderLine') as the first and therefore replace it.
If you do a print_r($nyorder) you will see that there is only one OrderLine

0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24343144
No, then you did something wrong, because that does not happen:
$nyorder = array(
  'CustomerCode' => '14593', 
  'OrderLines' => array(
    array('OrderLine' => array('ProductCode'=> '141707','OrderedQuantity' => '3000')),
    array('OrderLine' => array('ProductCode'=> '341432','OrderedQuantity' => '1000'))
  )
);
print '<pre>';
print_r($nyorder);
print '</pre>';
 
# result:
Array
(
    [CustomerCode] => 14593
    [OrderLines] => Array
        (
            [0] => Array
                (
                    [OrderLine] => Array
                        (
                            [ProductCode] => 141707
                            [OrderedQuantity] => 3000
                        )
 
                )
 
            [1] => Array
                (
                    [OrderLine] => Array
                        (
                            [ProductCode] => 341432
                            [OrderedQuantity] => 1000
                        )
 
                )
 
        )
 
)

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ShimodaFI
ID: 24343313
I tried that solution also but nuSoap chokes on it when it tries to serialize it to an XML. It can not convert it to a valid XML.

Unfortunately I have the code at my workplace so I can not show you the error msg from nuSoap. If there is any way to get nuSoap to accept this type of array my problem would be solved

0
 
LVL 39

Assisted Solution

by:Roger Baklund
Roger Baklund earned 2000 total points
ID: 24343999
Try this also, it is slightly different:
$nyorder = array(
  'CustomerCode' => '14593', 
  'OrderLines' => array('OrderLine' => array(
     array('ProductCode'=> '141707','OrderedQuantity' => '3000'),
     array('ProductCode'=> '341432','OrderedQuantity' => '1000'))
  )
);

Open in new window

0
 

Accepted Solution

by:
ShimodaFI earned 0 total points
ID: 24347145
Ok, I will try it first thing tomorrow  when I am back at work.
Will let you know what happens.

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question