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 Developer
Maximus09
Posts: 7
Registered: ‎03-12-2009
My Device: Not Specified

WIDGET > WEBSERVICE?

I do not see anything in the widget API for web services? How would a widget consume/submit to a webservice?
Please use plain text.
BlackBerry Development Advisor
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: WIDGET > WEBSERVICE?

Web Services can be handled many different ways in a Widget.  Basically the same types of options you would have from a web page.

 

1) You can go directly to the webservice passing down envelopes using the SOAP protocol by using a variety of JavaScript AJAX commands

 

2) You can create a RESTful web service that basically wraps the SOAP web service and return just the XML you want back to the device and then manipulate the response in JavaScript

 

3) You can create a web page via ASP, JSP, PHP etc to call the SOAP web service and return the resulting HTML back to the widget for display

 

It all depends on the what you are looking to accomplish.   For me, if I am calling a SOAP web service, I would typically choose either (2) or (3) so that I have the following advantages:

 

 

  • A layer of abstraction over the SOAP interface so that I control the contract with my mobile application and can abstract any changes in the SOAP interface so that it doesn't affect my mobile.  I.E. I would rather change my one abstraction point on the server instead of updating my X number of mobiles in the field
  • It also allows me to extract and only send back to the mobile the data that I want.  In many cases, existing SOAP interfaces are very verbose and have been designed for server-to-server data exchange.  They typically haven't been designed with mobile in mind.  So in some cases the SOAP interface can be providing a number of fields or pieces of data that my mobile doesn't care about.  
  • SOAP is a chatty protocol, and by isolating this protocol to the server, my application doesn't have to deal with the back and forth.
  • In a lot of my cases, I am hitting my web service not just for data exchange, but to generate a UI based on the results.  In this case I can save myself a lot of time and effort by just returning the HTML result from the server.  That way I don't have to manipulate the XML result and generate a UI on the fly via DHTML in JavaScript within the widget
That's my take on it :smileyhappy:

Cheers,

 

 

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
New Developer
AndrewPoirier
Posts: 1
Registered: ‎10-17-2009
My Device: Not Specified

Re: WIDGET > WEBSERVICE?

Can you be more specific about what ajax objects we can use?

 

I've just begun BB development so I'm not familiar with the envrionment.  I get an uncaught exception if I try to use the standard:

var http = XMLHttpRequest();

 

 

Any help is appreciated.  Thanks.

 

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

Re: WIDGET > WEBSERVICE?

 


AndrewPoirier wrote:

Can you be more specific about what ajax objects we can use?

 

I've just begun BB development so I'm not familiar with the envrionment.  I get an uncaught exception if I try to use the standard:

var http = XMLHttpRequest();

 

 

Any help is appreciated.  Thanks.

 


 

 

It appears that you have a syntax error in your code.. it should be:

 

var http = new XMLHttpRequest();

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
New Developer
dpicky
Posts: 57
Registered: ‎08-08-2008
My Device: Not Specified

Re: WIDGET > WEBSERVICE?

Tim

 

When you mention your preference to returning data in HTML as apposed to XML, would that still be the case if you were returning lots of records and fields intended for a SQLite table?  I recognise the size advantages of using HTML over XML, but would imagine one would have to get into delimiting fields, records etc. in order to strip the data out of the HTML.

 

I'm currently experimenting with migrating my MDS Runtime apps over to Widgets and in order to preserve the back office logic in the webservices have developed a 'wrapper' as you suggest in 3.  It returns the XML and then I use a JS framework from Prototypejs.org to parse the results which I then insert into a SQLite table.  It seems to work ok from the Browser and going to try as a Widget soon.  Are you aware of this product?  Do you think there are any potential pitfalls with this approach?

 

Look forward to hearing your feedback.

 

Dave

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

Re: WIDGET > WEBSERVICE?

Hi Dave,

 

If you are hitting a web service to then populate local data, then yes, bringing back XML is much better than HTML.  I'm not that familiar with the XML parser that you are using.  But the data that comes back from a AJAX request has already been parsed into a DOM for you.  The returned result is a Document in the responseXML property.

 

So you should just have to traverse the DOM of responseXML to pull out the values that you need.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
New Developer
fierro8
Posts: 4
Registered: ‎10-14-2009
My Device: Not Specified

Re: WIDGET > WEBSERVICE?

I am just getting started with BB widget development..., so forgive the elementary question.

 

How do you get around the cross domain xhr issue? Is that accomplished by whitelisting the domain in the config? This is what i am getting from reading some of the posts.

 

Also, when you mention AJAX libraries, I am guessing that JQuery would be fine. Yes?

 

 

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

Re: WIDGET > WEBSERVICE?

Yes, whitelisting the domain in the config will allow for cross domain xhr...

 

There are many parts of JQuery that will work.  Just note that the JQuery library is a "heavy" library so you may only want to strip out the pieces that you want.

 

Also note, that the Beta of the widget technology doesn't do any caching of pages or JavaScript so the JQuery library will be parsed each time it is loaded.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
New Developer
fierro8
Posts: 4
Registered: ‎10-14-2009
My Device: Not Specified

Re: WIDGET > WEBSERVICE?

Thanks for the quick reply and the insight.

 

Before I go off create my own light weight lib, can anyone recommend any lighter library that would support passing in multiple parameters (JSON data) to a WCF service?

 

Thanks in advance.

 

 

Please use plain text.
Contributor
missmanar1987
Posts: 32
Registered: ‎06-26-2010
My Device: all
My Carrier: stc

Re: WIDGET > WEBSERVICE?

Hi ..

Sir Tim ,

if I choose this way "

3) You can create a web page via ASP, JSP, PHP etc to call the SOAP web service and return the resulting HTML back to the widget for display" to be implemented in php do you have Guid how that accomplish ?

Please use plain text.