6 Replies Latest reply on Oct 24, 2013 6:11 AM by Ratish Nair

    How to make communication between Web Service and SB1 device

    Ratish Nair

      Hi,

      Recently we have purchased one SB1 device and I am developing an application in it.

       

      I wrote a simple HTML file and deployed the same in the respective path of the device and I am able to open the application successfully as well.

       

      The application has a textbox which will recieve the barcode of an item on scanning , this barcode will communicate with the web service function and return the desired result.

       

      As a next step , I tried invoking a web service method, but it got failed.

       

      Request you to send me a simple HTML and web service communication module which can help me to continue with my development further.

       

      Awaiting reply from your end.

        • Re: How to make communication between Web Service and SB1 device
          Daniel Silva

          This is most likely a cross domain issue. 

           

          You could probably verify this by looking in the rho log, which I think you will find in \UserDrive on the device.  I think the file name is log.txt.

           

          If your apps.json is pointing directly to the html file on the device, you could try pointing to the internal webserver.  This will change the protocol to http instead of file.  This may or may not solve the issue. 

          In other words, do

          http://127.0.0.1:83/UserDrive/my.html

          instead of

          /UserDrive/my.html

           

          If this doesn't help, you may be able to configure the webserver to allow cross domain requests. Look for CORS or "cross domain" in whatever docs are available for the server that is hosting your webservice..

           

          If that's not an option, how about hosting your web app on a web server and just pointing apps.json to the html page on the webserver?

            • Re: How to make communication between Web Service and SB1 device
              Ratish Nair

              Thanks Dany for your reply.

               

              I have applied the options that you have provided. Unfortunately the issue persists.

               

              As part of configuring the webserver to allow cross domain requests , I added the below code to web.config file in the root of web service application

               

              <system.webserver>

                   <httpprotocol>

                        <custom headers>

                             <add name ="Access-Control-Allow-Origin" value="*" />

                             <add name ="Access-Control-Allow-Headers" value="Content-Type">

                        </custom header>

                   </httpprotocol>

              </system.webserver>

               

              Shall I request you to send me a sample html and web service communication code, which can help me to proceed with my application development.

               

              Awaiting for your valuable response.

            • Re: How to make communication between Web Service and SB1 device
              Adel Sari

              Use jsonp for cross domain issue,

              i have 2 apps on SB1, one communicate with WCF web service, the other with PHP web service.

                • Re: How to make communication between Web Service and SB1 device
                  Ratish Nair


                  Can I request you to provide me communication code between web service and HTML from one of your application.

                   

                  Awaiting reply.

                    • Re: How to make communication between Web Service and SB1 device
                      Adel Sari

                      no problem,

                      on the SB1, this function for login page,

                          doLogin: function (p_userCode) {

                              var finalURL = service_base_url + '?method=LoginUser&userCode=' + p_userCode;

                              $.ajax({

                                  type: 'get',

                                  url: finalURL,

                                  dataType: 'jsonp',

                                  success: function (data) {

                                      var resultID = data["ResultID"];

                                      if (resultID == 1) {  //can login

                                          var userID = data["ID"];

                                          window.localStorage.setItem('userID', userID);

                                          window.location = 'process.html';

                                      }

                                      else if (resultID == 0) {

                                          alert('User code is not valid');

                                      }

                                  },

                                  error: function () {

                                      alert('Communication error');

                                  },

                                  async: true

                              })

                          }

                       

                       

                      for the server side, what framework are you using ?