Webservice reply

The forum to discuss the Headless version of Servoy. Web, Java and Servlet development questions can all be posted here.

Webservice reply

Postby martinh » Wed Feb 10, 2010 2:23 pm

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?
Martin
------------------------------------------------
Servoy Developer
Version 5.2.10/5.2.13
Java version 1.6 update 31
Database SQL Server 2008 R2
martinh
 
Posts: 857
Joined: Wed May 09, 2007 5:34 pm
Location: Belgium

Re: Webservice reply

Postby rgansevles » Wed Feb 10, 2010 5:02 pm

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
Rob Gansevles
Servoy
User avatar
rgansevles
 
Posts: 1927
Joined: Wed Nov 15, 2006 6:17 pm
Location: Amersfoort, NL

Re: Webservice reply

Postby martinh » Wed Feb 10, 2010 5:07 pm

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
Martin
------------------------------------------------
Servoy Developer
Version 5.2.10/5.2.13
Java version 1.6 update 31
Database SQL Server 2008 R2
martinh
 
Posts: 857
Joined: Wed May 09, 2007 5:34 pm
Location: Belgium

Re: Webservice reply

Postby rgansevles » Wed Feb 10, 2010 7:06 pm

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
Rob Gansevles
Servoy
User avatar
rgansevles
 
Posts: 1927
Joined: Wed Nov 15, 2006 6:17 pm
Location: Amersfoort, NL

Re: Webservice reply

Postby martinh » Wed Feb 10, 2010 7:52 pm

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)
Martin
------------------------------------------------
Servoy Developer
Version 5.2.10/5.2.13
Java version 1.6 update 31
Database SQL Server 2008 R2
martinh
 
Posts: 857
Joined: Wed May 09, 2007 5:34 pm
Location: Belgium


Return to Servoy Headless Client

Who is online

Users browsing this forum: No registered users and 7 guests