11 Replies Latest reply on Jan 17, 2012 8:56 AM by Timothy Murphy

    Accessing Web Services from a RhoElements Client

    Dino Gregorich

      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?

        • Re: Accessing Web Services from a RhoElements Client
          Gary Crean

          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.



          • Re: Accessing Web Services from a RhoElements Client

            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 .

            • Re: Accessing Web Services from a RhoElements Client
              Daniel Silva

              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?

              • Re: Accessing Web Services from a RhoElements Client
                Gary Crean

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


                header('Access-Control-Allow-Origin: *');
                $today = date("c");
                echo $today;


                And then on the device you have the follow.


                <!DOCTYPE HTML>
                <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";
                          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)
                <h1 id="message"><center>Please Wait</center></h1>