Accessing Web Services from a RhoElements Client

I've created several web services that expose ODBC and SQL Server data.  I can pass queries to retrieve data or send sql commands to insert or update data.  I've been able to write a client app in .NET that runs on the 9190 and other WM devices.  I've used this type of service for many years.  I can run in batch mode or connected mode easily.  However, RhoElements is JavaScript based.  With that said, I get "Access denied" errors when trying to access my web service from the device running RhoElements.  The cause of this is essentially the fact that the client / server relationship is crossing domains.  From what I have read, this causes the "error" (not really an error since it is the intention of JavaScript not to cross domains).  The Internet is full of people getting around this by running Ajax or JasonP.  I haven't figure that out yet, so before I spend the time, I want to ask:

Is there a better way to access web services from the Client side RhoElements without having to use Ajax, or JasonP or any other pseudo hacks?  Is there a RhoElements object that can access web services?  Or if anyone has been successful connecting to a web service, do you have a code snippet that you can share?

Gary Crean
I have also came across this

I have also came across this issue, I found the easiest way to solve this issue is to run a local web server on the device.

Thus the domain (Origin) is the same HTTP protocol. This also helps with being able to use AJAX with the application to

retrieve JSON objects.

I have convinced the development department to include the Web Server into RhoElements and I understand it will be released in

the future.

Gary

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Adel Sari
I have the same issue, my

I have the same issue, my application is used for long time under WM,  now with RhoElements i don't know how to connect to a Web service wich return a data (XML for example) to my application on ET1,

any body have a solution ? thnx

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
I've only been able to do it

I've only been able to do it via Java (Eclipse with Android/Moto plugins), not RhoElements at this time.  I was thinking that creating a Java applet to run in the RhoElements application might work, but I did not do that because I am hoping RhoElements will come out with the capability.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Juan-Antonio Ma...
I recently had this

I recently had this discussion with a partner and we concluded that the best way was writing a NPAPI plugin to interface RhoElements with Web Services.

Ideally in C++ rather than .NET, so only one framework has to be running: if written in .NET, CF has to be loaded in memory.

Also, using .NET increases CPU usage, since both javascript and C# "codes" are interpreted (managed, should I rather say?).

The idea was to expose to RhoElements all the common Web Services methods/functions, or even create higher-level ones.

Yes, I know it sounds like a huge task, but once written this could be reused by the community .

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
I've been playing with

I've been playing with porting a customer app to RhoElements from a native C++ app.  The current (C++) app does an HTTP GET call to a web server, but the data it retrieves is just text (not XML or JSON or any standard format).  If I run my Rho version as a device hosted app, even using the onboard webserver, I get security errors trying to get the text data from the server using XMLHttpRequest().  If I host the app on the same webserver that the text data is coming from, no problem.  The reading I've been doing seems to be saying that it can be done if you make changes to the host web server to set the domain to match the one on the page that's requesting the data, or use JSONP.  I don't think this customer will like any of those options.  I think they would very much prefer not to make any changes to the back end and just have a new RhoElements app that does just what their old app does, but is able to go cross platform.  Seems like the only way I might be able to make this work without touching the back end is to write a plugin as mentioned by Juan-Antonio. Am I missing something, or are these my only options?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Gary Crean
If your trying to use a web

If your trying to use a web service from another domain, The hosting server must allow this to happen. This is done by the server adding a header in the response. Adding a header of Access-Control-Allow-Origin: *

https://developer.mozilla.org/En/HTTP_access_control gives more information how this works. The reason a normal HTTP GET works within C++ is because it's the client side that does the checking (ie. Webkit)

The internal web server is used for AJAX requests against your application, For example JQuery-Mobile uses AJAX to load external pages. The file:// protocol due to security restrictions will not allow this.

Gary

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


George Mirabelli
Also take a look at the user

Also take a look at the user access privileges for the web user that the IIS webservice is using. if the website is running as a user that does not have the right access rights then you will get the access denied error.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Timothy Murphy
Gary,Given everything you

Gary,

Given everything you said trying to access a web service from another domain:

1. Enable local RE Webserver;

2. Application using JQuery/AJAX

3. Run Web Application via http://localhost

4. Add "Access-Control-Allow-Origin: *" header on hosting server

Still receiving a failure with "...Access is not allowed by Access-Control-Allow-Origin" ??  Any additional thoughts, or something else I may have missed?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Thanks Gary.  I thought that

Thanks Gary.  I thought that would be the answer, I just wanted to be sure I wasn't missing some other way to do this.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Dan, I can't offer any

Dan, I can't offer any specific help to your problem but I can tell you that there were several fixes to the XMLHttpRequest handling made in RhoElements 1.0.2 so make sure you're testing with that version or later.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Gary Crean
Here's an example of a php

Here's an example of a php script on a server the returns the date and time.

<?php

header('Access-Control-Allow-Origin: *');

date_default_timezone_set('UTC');

$today = date("c");

echo $today;

?>

And then on the device you have the follow.

<!DOCTYPE HTML>

<html>

<head>

<script type="text/javascript">

//This is a web-service i have running on the internet, It simply returns

//a date/time in a ISO8601 format.

//Expected format is yyyy-mm-ddThh:mm:ss.mmm+00.00

          var url="http:\\DOMAIN_NAME_HERE\\getTime.php";

 

          CheckTime();

          function CheckTime()

          {

                    var httpreq = new XMLHttpRequest();

                    httpreq.open("GET", url, true);

                    httpreq.onreadystatechange = function ()

                    {

                              var done = 4, ok = 200;

                              if (httpreq.readyState == done && httpreq.status == ok)

                              {

                                  alert('httpreq.responseText);

                              }

                    };

                    httpreq.send(null);

          }

</script>

<body>

<h1 id="message"><center>Please Wait</center></h1>

</body>

<head>

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Log in to post comments