Web Services Marshalling and Unmarshalling

Hi,

I am new to Servoy Web Services. I have just deployed a solution with ws_create method as a web service. I just noticed that when i return an object with sub objects in ws_create method it only returns a truncated xml file and does not continue with the xml response.

  1. Should I implement marshalling and unmarshalling of objects through JaxB in this method?
  2. Or did I miss out any Servoy’s feature that does this automatically?

Thanks!

I am just looking for a way to convert Javascript objects to XML data and vice versa. Any input is appreciated.

I haven’t tried this, but if you run your object thru either

uneval(jsobj)

or

plugins.serialize.toJSON(jsobj)

you should get back a string representation of it, and that should pass through XML fairly cleanly (as long as you don’t have any unsupported characters in your object)

The restful webservice plugin should automatically convert the JavaScript object to XML if the content-type of the request is XML.

If you say something goes wrong, please show what is happening.

Paul

pbakker:
The restful webservice plugin should automatically convert the JavaScript object to XML if the content-type of the request is XML.

If you say something goes wrong, please show what is happening.

Paul

Hi Paul, I included the summary of the error in my post. Here are the details:
I have message object with requestobject and other sub objects. When I return these objects in ws_create method, it generates a truncated xml response.

function ws_create()
{
   var messageObject = new Object("message");
   messageObject.message = "Successfully retrieved";
   messageObject.responseObject = new Object("responseObject");
   messageObject.responseObject.name = "Servoy" ;
   return messageObject;
}

The responseXML is: ```

<?xml version="1.0" encoding='UTF-8'?> ""message""

You are using the new Object constructor wrong.

This way your code works as expected:

function ws_create()
{
   var messageObject = new Object();
   messageObject.message = "Successfully retrieved";
   messageObject.responseObject = new Object();
   messageObject.responseObject.name = "Servoy" ;
   return messageObject;
}

You can also write the same thing even shorter:

function ws_create()
{
   return {message: "Successfully retrieved", responseObject: {name: "Servoy"}};
}

The way you used the Object constructor creates a new String object: https://developer.mozilla.org/en/JavaSc … t#Examples

Paul

Thanks very much. I will rewrite my code and test it.

Thanks, Paul. It worked.

I have another question on the client-side application regarding unmarshalling. I try to call my web service host through the following codes:

	plugins.http.createHttpClient('mybrowser');
	var poster = plugins.http.getPoster('http://x.x.x.x:1234/servoy-service/rest_ws/something_ws/ws_getsomethingdetails');
	var xmlData = "<xmldata></xmldata>";
	var didAddParam = poster.addParameter(null,xmlData);
	var httpCode = poster.doPost(); //httpCode 200 is ok
	var pageData = poster.getPageData();
	plugins.http.deleteHttpClient('mybrowser');

How do I convert the pageData from xml to javascript object? Does Servoy have automatic conversion?

Edit:
Is this how we call web service in Servoy?

Erik,

The plugin handles the formatting to/from http responses and body contents.
The currently supported content types are xml and json.
For both formats, the plugin handles the conversion, the js methods in your solution receive/return js objects.

You can control which content type to be used in the Content-Type and Accept http headers of your request.
By default the content type is derived from the content and the default response content type is the same as the request content type or json for GET.

Rob

rgansevles:
The plugin handles the formatting to/from http responses and body contents.

Are you referring to http plugin?

rgansevles:
The currently supported content types are xml and json.

Currently, I am using XML.

rgansevles:
For both formats, the plugin handles the conversion, the js methods in your solution receive/return js objects.

The variable, pageDate, from “var pageData = poster.getPageData();” returns an xml data and not js objects. Should this method be returning js object?

The source code in my previous post is all I execute to call my web service. Did I miss out an API call?

Erik,

I am talking about the server-side, for which you can use the rest_ws plugin.
In this plugin you deal with js objects, on the client side you deal with json or xml.

Rob