Page 1 of 1

Webservice reply

PostPosted: Wed Feb 10, 2010 2:23 pm
by martinh
Hi,

I'm doing my first steps on the new webservice.

I've seen how you can do a reply.

Code: Select all
var reply = new Object()
reply.elementname1 = value1
reply.elementname2 = value2


So far so good. But I want to give the following as a result:
Code: Select all
<Reply>
   <elementname1>value1</elementname1>
   <elementname2>value2</elementname2>
   <companies>
      <company>
         <id>123</id>
         <name>company123</name>
      </company>
      <company>
         <id>456</id>
         <name>company456</name>
      </company>
   </companies>
</Reply>



So I thought:

Code: Select all
var reply = new Object()
reply.elementname1 = value1
reply.elementname2 = value2
var companies = reply.companies = new Object()
var company = companies.company = new Object()
company.id=123
company.name=company123
var company = companies.company = new Object()
company.id=456
company.name=company456


This doesn't work. Maybe doing something with array of objects?
But how to do this then?

Re: Webservice reply

PostPosted: Wed Feb 10, 2010 5:02 pm
by rgansevles
Martin,

What about this:

Code: Select all
var reply = new Object()
reply.Reply = new Object()
reply.Reply.elementname1 = value1
reply.Reply.elementname2 = value2

var company1 = new Object()
company1.id = 123
company1.name = 'company123'

var company2 = new Object()
company2.id = 456
company2.name = 'company456'

reply.Reply.companies = [company1, company2]


Rob

Re: Webservice reply

PostPosted: Wed Feb 10, 2010 5:07 pm
by martinh
Rob,

How do you get those company1, company2, ...., companyx attached to that reply?

Or is there a way that I can use the XML-plugin of Drmaison and put final XML into an object so that it can be replied?

But that means that I need something like:

var reply = new Object()
reply.Reply = xmldocument.convertToObject()

and I don't see such a method

Martin

Re: Webservice reply

PostPosted: Wed Feb 10, 2010 7:06 pm
by rgansevles
martinh wrote:How do you get those company1, company2, ...., companyx attached to that reply?

Did you try my sample above?

martinh wrote:Or is there a way that I can use the XML-plugin of Drmaison and put final XML into an object so that it can be replied?

No, the conversion from object to xml is done iside the plugin.

Rob

Re: Webservice reply

PostPosted: Wed Feb 10, 2010 7:52 pm
by martinh
rgansevles wrote:
martinh wrote:How do you get those company1, company2, ...., companyx attached to that reply?

Did you try my sample above?



Whatever I try, I don't get the XML below:
Code: Select all
    <Reply>
       <elementname1>value1</elementname1>
       <elementname2>value2</elementname2>
       <companies>
          <company>
             <id>123</id>
             <name>company123</name>
          </company>
          <company>
             <id>456</id>
             <name>company456</name>
          </company>
       </companies>
    </Reply>


The list with companies is unlimited.

Could it be an option to generate a long string and then make it an object using:

Code: Select all
      plugins.serialize.fromJSON(String)