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.
Should I implement marshalling and unmarshalling of objects through JaxB in this method?
Or did I miss out any Servoy’s feature that does this automatically?
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)
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;
}
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?
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.
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.