Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
New Contributor
xavirm
Posts: 8
Registered: ‎01-24-2011
My Device: Curve 8530
My Carrier: Iusacell

Re: How "I" would call a web service from a Widget [Example Included]

OK, you are going to want to kick my head, and I'll give you the reason :smileyhappy:

Debuging, I found out that responseText brought something like http://localhost... has no permissions ..." (or something like that).

So I realized in that moment that I hadn't include the port :smileyhappy:

So, when I included the domain http://localhost:9198 in my config.xml everything worked fine.

Thanks a lot.

I'll keep working in this so don't expect me to let you rest :smileyhappy:

Regards,

 

Paco

 

 

Please use plain text.
Contributor
the_hornet
Posts: 10
Registered: ‎11-30-2010
My Device: Not Specified

Re: How "I" would call a web service from a Widget [Example Included]

Hi, does this work in getting data from an MS SQL Database?

As the widget I am developing for my project for my foundation degree needs to access the data held ther and I am finding it difficult to find out how to get the data into my widget. (I am a newbie to blackberry development)

 

Many Thanks

 

Darren

Please use plain text.
BlackBerry Development Advisor
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: How "I" would call a web service from a Widget [Example Included]

Hi Darren,

 

This approach would work for remotely accessing a server side MS SQL Database that you wrap a web service layer around.  

 

You cannot package a database file locally inside your WebWorks application.  For local data you need to dynamically create a SQLite database and populate it through JavaScript

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
New Contributor
xavirm
Posts: 8
Registered: ‎01-24-2011
My Device: Curve 8530
My Carrier: Iusacell

Re: How "I" would call a web service from a Widget [Example Included]

Hello,

As Tim told you, I would recommend building a web service layer to access SQL Server and then your webworks app consuming this services.

Good luck.

Best regards,

Please use plain text.
Developer
miamon
Posts: 181
Registered: ‎08-17-2008
My Device: Red BlackBerry Z10
My Carrier: Vodafone

Re: How "I" would call a web service from a WebWorks App[Example Included]

Easy way for Serialize to JSON from .NET Server:

 

System.Web.Script.Serialization.JavaScriptSerializer 
toJson = new System.Web.Script.Serialization.JavaScriptSerializer();
return toJson.Serialize(this);

http://msdn.microsoft.com/en-us/library/bb292287.aspx

Josep Maria
Please use plain text.
Contributor
aubjf
Posts: 23
Registered: ‎05-11-2011
My Device: 9800 BOLD
My Carrier: Videotron

Re: How "I" would call a web service from a WebWorks App[Example Included]

Hi,

 

I was never able to make your code work ( don't know why but, in my case, xmlHttp.readyState always return 1 ).

So I search a other way for accessing my web service and I found this code looking very similar to your's.

It work pretty well on remote/local web service and on OS5 (9800 Simulator) and Tablet OS (Playbook Simulator)

 

<!

DOCTYPEhtmlPUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">

<

html><head><metaname="viewport"id="viewport"content="initial-scale=1.0,user-scalable=no"/><scripttype="text/javascript"src="json_sans_eval.js"></script><scripttype="text/javascript">

function

doClick()

{

ajaxRequest();

}

function

ajaxRequest()

{

var ajaxrequest = new XMLHttpRequest( );

ajaxrequest.onreadystatechange =

function( )

{

if( ajaxrequest.readyState == 4 && ajaxrequest.status == 200 ) handleContent (ajaxrequest.responseText);

}

ajaxrequest.open(

'GET', 'http://your service address, true);

ajaxrequest.send( );

}

functionhandleContent(content) {

 

content.replace(/&lt;/g,

"<").replace(/&gt;/g,">");

document.getElementById(

'div_result').innerHTML = content;

 

}

</script></head><body><buttononclick="doClick()">Get Async Response </button><divid="div_result"></div></body>

</

html>

 

 

  

Please use plain text.
Retired
mwoolley
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: How "I" would call a web service from a WebWorks App[Example Included]

FYI we have another article which explores the subject of WebWorks development and web services:

 

http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/LAB-Create-a-typical-mobile-ente...

 

Full source included.

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Please use plain text.
Contributor
aubjf
Posts: 23
Registered: ‎05-11-2011
My Device: 9800 BOLD
My Carrier: Videotron

Re: How "I" would call a web service from a WebWorks App[Example Included]

Hi,

 

This is a very usefull example but can you please provide example with Microsoft base web service.

And by the way can you provide example without JSon output because I already have my web service

and I don't want to recode it (and all other caller) just to fit with your example.:Dots:

 

And before leaving you when I test this function ( 9800 OS6 simulator) ...I don't know why but the

alert('2') raise before alert('1')...and in some case the row was inserted and in other

they don't without raising a error in a try catch. And for some reason I don't find explanation for

the same row have several alert('2') for one alert('1')...it look like the while loop work in reverse

mode...:Sorcerer:

 

This is my parser...have fun:

 

function ParsePageFromXMLtoData(contentXML){

 

 

var iposDebut;

var iposFin;

var iposDebutBloc;

var iposFinBloc;

var content;

var contentBloc;

var PageID;

var PageTitre;

var PageMotCle;

var PageCouleurFond;

var PageDerniereModif;

var i;

var bInserted;

 

i=1;

 

contentXML.replace(/&lt;/g,"<").replace(/&gt;/g,">");

 

content=contentXML;

 

while (contentXML.indexOf("&lt;/PAGE&gt;") > 0){

 

bInserted=false;

 

content=contentXML;

 

iposDebut = content.indexOf("&lt;PAGE&gt;");

iposFin = content.indexOf("&lt;/PAGE&gt;");

 

content = Mid(content,iposDebut + 12,iposFin-iposDebut + 1);

 

iposDebutBloc=content.indexOf("&lt;BLOCS&gt;");

iposFinBloc=content.indexOf("&lt;/BLOCS&gt;");

 

contentBloc= Mid(content,iposDebutBloc + 13,iposFinBloc-iposDebutBloc + 1);

contentXML = Mid(contentXML,iposFin-iposDebut + 13, contentXML.length - iposFin )

 

//ID

iposDebut = content.indexOf("&lt;ID&gt;");

iposFin = content.indexOf("&lt;/ID&gt;");

PageID = Mid(content,iposDebut + 10,iposFin-10);

content = Mid(content,iposFin + 11 ,content.length-iposFin + 11);

 

//TITRE

iposDebut = content.indexOf("&lt;TITRE&gt;");

iposFin = content.indexOf("&lt;/TITRE&gt;");

PageTitre = Mid(content,iposDebut + 13,iposFin-13);

content = Mid(content,iposFin + 14 ,content.length-iposFin + 14);

 

//MOTCLE

iposDebut = content.indexOf("&lt;MOTCLE&gt;");

iposFin = content.indexOf("&lt;/MOTCLE&gt;");

PageMotCle = Mid(content,iposDebut + 14,iposFin-14);

content = Mid(content,iposFin + 15 ,content.length-iposFin + 15);

 

//COULEURFOND

iposDebut = content.indexOf("&lt;COULEURFOND&gt;");

iposFin = content.indexOf("&lt;/COULEURFOND&gt;");

PageCouleurFond = Mid(content,iposDebut + 19,iposFin-19);

content = Mid(content,iposFin + 20 ,content.length-iposFin + 20);

 

//DERNIEREMODIF

iposDebut = content.indexOf("&lt;DERNIEREMODIF&gt;");

iposFin = content.indexOf("&lt;/DERNIEREMODIF&gt;");

PageDerniereModif = Mid(content,iposDebut + 21,iposFin-21);

content = Mid(content,iposFin + 22 ,content.length-iposFin + 22);

 

Alert('1');

 

if (db) {

db.transaction(function (tx) {

tx.executeSql("SELECT * FROM t_page WHERE PageID = ?", [PageID], function (ax, results) {

 

if (results.rows.length>0){ bInserted=true;}

 

if (bInserted=true)

{

 

Alert('2');

uppage(PageID,PageTitre,PageMotCle,PageCouleurFond,PageDerniereModif);

 

}

else

{

 

if (bInserted==false){

Alert('2');

tx.executeSql('INSERT INTO t_page(PageID,PageTitre,PageMotCle,PageCouleurFond,PageDerniereModif) VALUES (?,?,?,?,?)',

[PageID,PageTitre, PageMotCle, PageCouleurFond, PageDerniereModif]);

bInserted=true;

 

 

}

 

 

}

});

});

}

 

i=i+1

ParseBlocFromXMLtoData(contentBloc)

 

}

}

 

Please use plain text.
New Contributor
kmckenna
Posts: 3
Registered: ‎05-03-2011
My Device: Tour
My Carrier: Sprint

Re: How "I" would call a web service from a WebWorks App[Example Included]

Hi I am trying to get this working. I am running Blackberry Webworks Portal 2.1.1.3.8

Windows 7

Java 1.6

Simulator 9550

Phonegap 1.0

MDS that comes with BBWP (I needed to add a proxy port)

 

I can get to the internet via browswer. I added some things so I can see what is going on. It works when I run it directly in Firefox.

 

My phone gap app javascript&colon;


    var xmlHttp = new XMLHttpRequest();

    function init2() {
        var url = "http://ws.geonames.org/postalCodeSearchJSON?postalcode=90210&maxRows=10";
                xmlHttp.open('GET', url, true);
                xmlHttp.onreadystatechange = callbackFunction;
                xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                document.getElementById('results').innerHTML = "Requesting...";
                xmlHttp.send(null);

    }
      function callbackFunction(){
        if (xmlHttp.readyState != 4)
          return;
            document.getElementById('results').innerHTML = "ready...";

//i commented this out because it just stopped here.
          //var codes = eval("("+xmlHttp.responseText+")").postalCodes;
          //var nameVar = codes[0].placeName;


//I am trying to see the actual response to see if parsing the json caused it to not work

       document.getElementById('results').innerHTML = xmlHttp.responseText;
        //document.getElementById('results').innerHTML = nameVar;
      }

<body onload="init2()" onunload="unload()">

    <h1 id="results">
      results
    </h1>

  </body>
</html>

 

 

This is the response i get in the simulator:

Client Error: URL request was filtered.

Yuur request cannot be serviced due to access restrictions. Please contact your System Administrator for further details

 

Thank you for your help.

Please use plain text.
New Contributor
kmckenna
Posts: 3
Registered: ‎05-03-2011
My Device: Tour
My Carrier: Sprint

Re: How "I" would call a web service from a WebWorks App[Example Included]

I have this in my config


  <!-- Expose access to all URIs, including the file and http protocols -->
  <access subdomains="true" uri="*" />

Please use plain text.