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
Highlighted
New Contributor
Posts: 7
Registered: ‎03-28-2011
My Device: BlackBerry® Curve™ 8500
My Carrier: Airtel
Accepted Solution

How to call web service in blackberry sdk 3.6 using eclipse

[ Edited ]

 

Hi buddy
   
   How to call the web service in Blackberry sdk 3.6 plugging using eclipse?
   Please can any one help me,where I went wrong in this code.
   Here I added code along with this post, its work in Html.
   while I trying to implement in Blackberry sdk application it shows some error.
Error:
<!--
TypeError: undefined is not a function.
 Running  at line    3: service.useService("http://www.w3schools.com/webservices/tempconvert.asmx?wsdl","temp");}.
 Called from line    1: InitializeService()} } } }.
TypeError: Cannot convert 'undefined' to an object.
 Running  at line    9: service.temp.callService("CelsiusToFahrenheit",celcius);}.
 Called from line    1: Getfahrn()} } } }.
TypeError: undefined is not a function.
 Running  at line    3: service.useService("http://www.w3schools.com/webservices/tempconvert.asmx?wsdl","temp");}.
 Called from line    1: InitializeService()} } } }.
--!>
 
Code:
--------
<html>
<head>
<title>CelsiusToFahrenheit</title>
<script type="text/JavaScript">
function InitializeService()
            {
                service.useService("http://www.w3schools.com/webservices/tempconvert.asmx?wsdl","temp");
            }
            function Getfahrn()
            {
               
                var celcius = document.DemoForm.cel.value;              
                service.temp.callService("CelsiusToFahrenheit",celcius);
            }
            function ShowResult()
            {
                 var xml= event.result.value;
                 document.write("<div style='width:250;background-color:#008080;font-size:18'>Celsius To Fahrenheit : ",
                 xml +"       </div>");
            }

 

            function InitializeService()        

            {                

                 service.useService("http://www.w3schools.com/webservices/tempconvert.asmx?wsdl","temp");  

            }           

            function Getfahrn()      

     {                  

                       var celcius = document.DemoForm.cel.value;      

                       service.temp.callService("CelsiusToFahrenheit",celcius);   

         }         

   function ShowResult()  

         {  

                     var xml= event.result.value; //var json = $.xml2json(xml); document.write("<div

                     style='width:250;background-color:#008080;font-size:18'>Celsius To Fahrenheit : ", xml +"</div>");

          }

 

</head>

<body onload="InitializeService()"  onresult="ShowResult()" id="service" style="behavior:url(webservice.htc);background-color:#008080;font-size:18">

<form name="DemoForm">

 <center>

 Temperature Coversion<br/><br/>

 <table>

        <tr>

             <td>Celsius To Fahrenheit </td>

             <td> <input type="text" name="cel"/></td>

             <td><button onclick="Getfahrn()">Submit</button></td>

    </tr>

 </table>

</center>

</form>

</body>

</html>

 

 

 

---------------------------

 

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: How to call web service in blackberry sdk 3.6 using eclipse

I can't see anywhere that you have defined/declared the "service" object.  Are you linking in a JavaScript toolkit of some sort?

 

What is happening, is that when the JavaScript engine trys to find "service." it cannot find it anywhere.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
New Contributor
Posts: 7
Registered: ‎03-28-2011
My Device: BlackBerry® Curve™ 8500
My Carrier: Airtel

Re: How to call web service in blackberry sdk 3.6 using eclipse

Hi

 

    I declared there  <body id=service>

    Its work fine when i run as html in IE broswer.

   while i try to run in webworks, its gives error. 

 

thanks

Balaji

 

 

 

 

  

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: How to call web service in blackberry sdk 3.6 using eclipse

it looks like you are using some kind of .NET specific web services call.  Does this same call work in Chrome?  Or does it only work in IE.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
New Contributor
Posts: 7
Registered: ‎03-28-2011
My Device: BlackBerry® Curve™ 8500
My Carrier: Airtel

Re: How to call web service in blackberry sdk 3.6 using eclipse

Hi

 

   It work only in IE not in chrome.

 

   Pls help me, where i went wrong in this code...

 

 

Thanks

Balaji

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: How to call web service in blackberry sdk 3.6 using eclipse

The issue is that you are using IE and .NET specific code.  The Browser on a BlackBerry is WebKit based (same engine behind chrome).   Using .NET/IE specific code will not run on BB, iOS, Android, WebOS.. it will only run on IE

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
New Contributor
Posts: 7
Registered: ‎03-28-2011
My Device: BlackBerry® Curve™ 8500
My Carrier: Airtel

Re: How to call web service in blackberry sdk 3.6 using eclipse

Hi

 

    Pls can u suggest me, what is solution to run in BB.

 

Thanks 

Balaji

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: How to call web service in blackberry sdk 3.6 using eclipse

Here is a thread that I had created around calling web services using standard AJAX calls.

 

http://supportforums.blackberry.com/t5/Web-Development/How-quot-I-quot-would-call-a-web-service-from...

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
New Contributor
Posts: 7
Registered: ‎03-28-2011
My Device: BlackBerry® Curve™ 8500
My Carrier: Airtel

Re: How to call web service in blackberry sdk 3.6 using eclipse

[ Edited ]

Hi

 

    I tried above given link example to call web service.

    Still its run only in IE, not in other browser.

    Pls help me to get out of this trouble.

 

 

thanks

Balaji

New Developer
Posts: 70
Registered: ‎01-13-2011
My Device: Torch 9800 and Playbook
My Carrier: Rogers

Re: How to call web service in blackberry sdk 3.6 using eclipse

Balaji, you're clearly not following the link Tim provided if this still isn't working. The code you've shown above makes a call to service.useService. (For those of you following along at home, turns out there's a really bizarre feature in IE that lets you call a webservice and control the loading and callback method based on an element in your DOM. More infor here, http://www.webreference.com/js/column98/6.html )

 

useservice is only supported in Internet Explorer. IE has a long history of supporting non-standard APIs. You shouldn't use these APIs for because you'll run into issues on other browsers. The Playbook browser is based on the Webkit engine, which also underlies Chrome and Safari. It's generally considered one of the top rendering engines out there, so you should be happy you have access to it. 

 

Instead of using useService, make a normal Ajax call to your webservice. You can do this with a straight XmlHttpRequest object, but I'd suggest using a library like jQuery. Search for a SOAP plugin for jQuery to make parsing the response easier. 

 

You're asking a very general web development question, and you would probably benefit from reading some of the tutorials on the jQuery site, or the JavaScript tutorials on the Mozilla developers site https://developer.mozilla.org/en/JavaScript/Guide