Rest problem return json to .NET

Using Servoy to administrate the content of your website? Discuss all webrelated Servoy topics on this forum!

Rest problem return json to .NET

Postby mmcmanus » Fri Apr 13, 2012 7:05 pm

Have a problem with a clients who is using .NET to access our rest service. A simple url query returns XML, but using .NET we keep getting JSON returned. I was wondering if anyone has seen this? Its bringing our work to a bit of a halt.

Here is their code. I have asked for the response data, but have not received yet. "test_cases" is the actual get request. The last two strings are part of the query. The addition of the request type has been added for testing and does not work, with or without. I am not a .NET person, so am at a bit of pickle here.

[code] string myurl = "https://url.com/servoy-service/rest_ws/solution/test_cases/MilwaukeeXXX/5966598";

WebRequest myrequest = WebRequest.Create(myurl);

myrequest.ContentType = "application/xml";

WebResponse myresponse = myrequest.GetResponse();

Stream objstream;

StreamReader objReader;

objstream = myresponse.GetResponseStream();

objReader = new StreamReader(objstream);

String results = objReader.ReadToEnd();
[/code]

Thanks for any help.

A little more detail. The request seems to be returning this to .NET. This is not what I return from Servoy, what I get when Browser query or

{\"request\":{\"cases\":{\"id\":\"1102232\",\"client_id\":\"5966598\",\"testsets\":{\"docket_number\":\"12PA000184\",\"date_reported\":\"03/13/2012\",\"parties\":{\"party\":[{\"testrole\":\"Mother\",\"id\":\"1102232-10\",\"lastname\":\"Amador*\",\"firstname\":\"Yesenia\"},{\"testrole\":\"Child\",\"id\":\"1102232-20\",\"lastname\":\"Garcia\",\"firstname\":\"Juan\"},{\"testrole\":\"Alleged Father\",\"id\":\"1102232-30\",\"lastname\":\"Olmedo\",\"firstname\":\"Juan\"}]},\"testid\":46638,\"client_id\":\"5966598\",\"percent_probability\":\"99.99999997%\",\"report_file_ext\":\"<link rel=\\\"self\\\" href=\\\"http://url.com/servoy-service/rest_ws/ddc_rest/files/doc/Milwaukeexxxx/495813.pdf/>\",\"report_file_flag\":\"true\"}},\"success\":\"1\"}}
mmcmanus
 
Posts: 41
Joined: Thu Feb 23, 2006 7:28 pm
Location: Cincinnati, OH

Re: Rest problem return json to .NET

Postby mmcmanus » Fri Apr 13, 2012 9:56 pm

More information here. Wiztools est client and Servoy 3.5 get a json return also.

The docs say: By default, the plugin will respond with the same Content Type as was specified in the HTTP Request. This can be overruled by specifying a different response Content-Type in the Accept header of the HTTP Request: Accept: application/json

How does one explicitly set the headers from the server so I always return xml? This seems to be the problem. Unless I am missing something. Seems like there should be something in the server setting sfor this.
mmcmanus
 
Posts: 41
Joined: Thu Feb 23, 2006 7:28 pm
Location: Cincinnati, OH

Re: Rest problem return json to .NET

Postby ptalbot » Fri Apr 13, 2012 10:28 pm

Seriously you should have a look at the new Velocity Web client: https://www.servoyforge.net/projects/velocity-report/wiki/WebClient

You would then configure your solution's config.json like this:
Code: Select all
test_cases: {
    type: 'session',
    pages: {
        "*": { ajax: 'xml' }
    }
}

:)
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
https://www.servoyforge.net
Velocity rules! If you don't use it, you don't know what you're missing!
User avatar
ptalbot
 
Posts: 1654
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

Re: Rest problem return json to .NET

Postby mmcmanus » Fri May 04, 2012 4:26 pm

I wanted to give at least the answer I have resolved this with, since it does not seem the service can be forced from the dev side.

When using an http request. Use the accept request header from the client side. This at least makes Servoy return the XML

Something like: http_request.setRequestHeader("Accept", "text/xml");
mmcmanus
 
Posts: 41
Joined: Thu Feb 23, 2006 7:28 pm
Location: Cincinnati, OH


Return to Web Development

Who is online

Users browsing this forum: No registered users and 3 guests