BlackBerry and .NET Web Service Tutorial – Part 1

June 22, 2009 by Craig in stuff

Setting up Eclipse and Installing KSoap2 on the BlackBerry 

First of all, do yourself a favour. Just download the Full JDE Plugin, it includes Eclipse. I started by installing a vanilla Eclipse and getting the plugins after, it wasn’t worth the hassle for me. I’m using version 1.0.0.67

Now fire it up and let’s start.

  1. Create a new workspace.
    gallery thumbnail
  2. Create a new BlackBerry Project. File > New > Project Select BlackBerry project named ?Sample?.(Figure 2)
  3. Create another new BlackBerry Project named ‘KSoapLibrary’ (Figure 3).
    gallery thumbnailgallery thumbnail
  4.  Open the Project Properties for KSoapLibrary. Go the ‘BlackBerry Project Properties’ and click the ‘Application’ tab. From the Project Type drop down select Library (Figure 4). Click OK.
    gallery thumbnail
  5.  Now we need to add the KSoapLibrary as a project reference to the Sample project. Go to the Project Properties for Sample, click the Project References and select the KSoapLibrary checkbox (Figure 5).  Click OK.
    gallery thumbnail
  6.  It’s time to create a class within our Sample project. Select New > Class. Set the class and packages names (Figure 6). Click Finish.
    gallery thumbnail
  7. Add the contents of the HelloWorld.java file found in the Resources section at the bottom of this page to your new class.
  8. Eclipse will now give you a number of errors in the file (Figure 7).  This is because Eclipse does not have the KSoap files within the build classpath. Let’s fix that.
    gallery thumbnail
    • Create a folder within the KSoapLibrary project named ?lib? and add the ksoap2-j2me-core-prev-2.1.2.jar file to the new folder. The pre-verified ksoap file is VERY important. You can either preverify it yourself ordownload ksoap2-j2me-core-prev-2.1.2.jar now.
    • In the Sample project properties. Click on the ?Java Build Path? item, then the ?Libraries? tab. Finally, click ?Add Jars??. Select the KSoap jar, then click OK. Now click on the ?Order and Export? tab and select the KSoap jar and click OK (Figure 8).
      gallery thumbnail
    • Now your Eclipse Package Explorer should like the screen shot below, and the error will have disappeared (Figure 9).
      gallery thumbnail
  9. Finally, create another folder under your Samples project named ?images? and add an icon to it. Now go to your project properties then ?BlackBerry Project Properties? and add some information to the ?General? tab and add your icon from the ?Resources? tab (Figure 10).
    gallery thumbnail
  10. Done! Now Run it!
    gallery thumbnail

Didn’t work?

Common problems may include ?Error Starting Sample: Module ?ksoap2-j2me-core-prev-2.1.2? not found.? I struggled with this for some time. Go back and retrace your steps, you?ve skipped over something. Even though it compiles fine within Eclipse the ksoap jar has not been deployed to the device along with the rest of your code. I have noticed an annoyance where the KSoap jar will be removed from the Properties > Java Build Path ?Libraries? and ?Order and Export? tabs if you make any further changes to the ?BlackBerry Project Properties?. You?ll have to go back in and re-add the jar.
gallery thumbnail

The next example will build off of this and demonstrate how to connect to a .NET web service.

Resources: 

Leave a Reply

craigagreen.com  /  stuff  /  Current Page