BlackBerry Forums Support Community               

View Poll Results: Please rate the post
Poor 0 0%
Passable 0 0%
Good 0 0%
Excellent 0 0%
Voters: 0. You may not vote on this poll

Closed Thread
 
LinkBack Thread Tools
Old 08-13-2009, 11:34 PM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Aug 2009
Model: 8300
PIN: N/A
Carrier: Vodafone
Posts: 22
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Using KSoap2 for Blackberry Tutorial. The one without ambiguities!!!

Please Login to Remove!

Firstly this is my first post as a tutorial. So please don't care about short comings. I myself went through a lot of tutorials to develop a simple application on a blackberry device but sadly dint get much information. So this is for all those people who tried and dint get far and neither got much help..


I am using Eclipse ver 3.4.0( Apparently 3.4.1 is also supported but dint work for me), BlackBerry_JDE_PluginFull_1.0.0.67 , and ksoap2 which i am attaching here and simulators of ur choice (again only device software ver 4.3 and above)

If u r downloading the Ksoap2 library from elsewhere please make sure that it is preverified.

Step 1:
Create a new Blackberry Project.
After Creating a new project->Right click on the project->Project Properties-> Blackberry Project Properties-> Application->Project type->Library

Step 2:
Create a folder called "lib" at this new library project.

Step3:
Copy the ksoap2 preverified at this post to the lib folder. Right click on the file and select "Add to build path"

Step 4:Now Just build it once. Now your ready to use this is your application.

For your application.

Step5:In the Object explorer create a new project .

Step 6: Right click on the project -> Properties -> Java Build Path -> Libraries -> Add Jars... select Ksoap2.jar

Step 7: If you have noticed in previous posts many people have mentioned to add the created library to the project dependencies.. But there is no such option in Eclipse. It is only there if you use Blackberry JDE and yu are better off not using it in case you dont have any experience in Java cos it simply isnt worth it.


what you need to do here is right click on the project and there will be an option to add Project references. Click on it and it will contain the previous library project that you created. (P.S. You wont find it if its not in the same workspace). Check it and give add.

Thats it . Your done. You can go ahead and use the library. It will work like a charm..

Post back for Queries. All suggestions and criticisms welcome..Happy Coding!!!

P.S.
The preverified file and sample code that i have attached was taken from a previous post by Sickned.. I thank him for helping me get started.


And this is some sample code to access a .Net web service that i got from another post by Jackerlinn..
I thank hims for his post as well..
Code:
Below is simple code to call a .Net web service:

code extract from java file:
String serviceUrl = "<url to web service>l";
String serviceNamespace = "h t t p : / / tempuri . org /";
String soapAction = "h t t p : / / tempuri.org / HelloWorld";

SoapObject rpc = new SoapObject(serviceNamespace, "HelloWorld");

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

envelope.bodyOut = rpc;
envelope.dotNet = true;
envelope.encodingStyle = SoapSerializationEnvelope.XSD;

HttpTransport ht = new HttpTransport(serviceUrl);
ht.debug = true;

try
{
ht.call(soapAction, envelope);

String result = (envelope.getResult()).toString();


}
catch(org.xmlpull.v1.XmlPullParserException ex2){

}
catch(Exception ex){
String bah = ex.toString();

}


Code Extract from .Net web Service
namespace TestService
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "h t t p : / / tempuri . org /")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{

[WebMethod]
public string HelloWorld()
{
return "Hello World" + System.DateTime.Now.ToString();
}
}
}
Attached Files
File Type: zip Ksoap2LibPrev_and_sample_code.zip (42.8 KB, 443 views)

Last edited by nirmalsat : 08-13-2009 at 11:43 PM. Reason: Added Sample code
Offline  
Old 08-18-2009, 04:24 PM   #2 (permalink)
New Member
 
Join Date: Aug 2009
Model: 8830
PIN: N/A
Carrier: Sprint
Posts: 1
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok well I am having problems.

Step 1: No problem
Step 2: do I right click on the project and select New>Folder then name it lib?
Step 3: what is this ksoap2 preverified? do you mean ksaop2demo.java? and when i right click i don't have the option to add it to the build path. could you clarify that? This step really throws me off.
Step 4: No Problem

Step 5: No Problem
Step 6: No Problem
Step 7: No Problem
Offline  
Old 08-19-2009, 11:06 AM   #3 (permalink)
Knows Where the Search Button Is
 
Join Date: Aug 2009
Model: 8300
PIN: N/A
Carrier: Vodafone
Posts: 22
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi,
For step 2 , yes you need to right click on the project and click new and then nam the folder as lib.

After this download the attachment given above. It will have two files in it. You could jus drag the file from windows and drop it in to the lib folder in eclipse directly into the pane.

Then right click on the added file and select build --> Add to build path.
Offline  
Old 08-23-2009, 04:37 AM   #4 (permalink)
New Member
 
Join Date: Aug 2009
Model: 7100T
PIN: N/A
Carrier: asd
Posts: 9
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

dont work .... "Error starting Class Module ksoap2-j2me-core-prec-212 not found"
step 1 to 6 done
what do you mean with step 7?
Offline  
Old 08-23-2009, 08:33 AM   #5 (permalink)
New Member
 
Join Date: Aug 2009
Model: 7100T
PIN: N/A
Carrier: asd
Posts: 9
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

this works:

h tt p :/ /craigagreen.com/index.php?/Blog/blackberry-and-net-webservice-tutorial-part-1.html]craigAgreen - BlackBerry and .NET Web Service Tutorial - Part 1
Offline  
Old 08-23-2009, 11:17 AM   #6 (permalink)
Knows Where the Search Button Is
 
Join Date: Aug 2009
Model: 8300
PIN: N/A
Carrier: Vodafone
Posts: 22
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Wirelessly posted

Yes. I have seen the post that you have mentioned here. But mine should work as well. How did u add the library to the project.. Check the actual path of the Lib folder that you created. Does it contain the file??
Offline  
Old 10-21-2009, 07:57 AM   #7 (permalink)
New Member
 
Join Date: Aug 2009
Model: 8300
PIN: N/A
Carrier: email
Posts: 6
Post Thanks: 0
Thanked 0 Times in 0 Posts
Angry problen in Ksoap

Hello i am sorry to ask you this but have you ever work on eclipse plug-in or not.If yes which version u r using.i don't get any bulid.......>add to build path option.
Thanks.

Last edited by Sujit : 10-21-2009 at 08:15 AM.
Offline  
Old 10-21-2009, 10:18 AM   #8 (permalink)
Knows Where the Search Button Is
 
Join Date: Aug 2009
Model: 8300
PIN: N/A
Carrier: Vodafone
Posts: 22
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am sorry if i misguided u Sujit.. Anyways the version of eclipse and the plugin have all been mentioned at the begining of the post , if u would just care to read it properly..
Offline  
Old 11-18-2009, 07:07 PM   #9 (permalink)
New Member
 
Join Date: Nov 2009
Model: 9000
PIN: N/A
Carrier: DOCOMO
Posts: 3
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

please, help me.
I followed your steps.
But In my Simulator, 9000_Docomo can not find the module.

my environment is that :
BlackBerry JDE Component Package 4.5.0
Eclipse Platform Version: 3.4.1

please...help..me..
Offline  
Old 11-18-2009, 10:45 PM   #10 (permalink)
Knows Where the Search Button Is
 
Join Date: Aug 2009
Model: 8300
PIN: N/A
Carrier: Vodafone
Posts: 22
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Pls make ur question is clear.. Did u mean to say that it says cannot find module Ksoap2 preverified... If that is the case , its probably cos u ve not added the ksoap2.jar file properly.. Remove the folder and the jar and add it again.. Pls make sure that when u create the Lib folder , u add it to the project root.

Last edited by nirmalsat : 11-18-2009 at 10:46 PM. Reason: Typos
Offline  
Old 11-29-2009, 07:08 AM   #11 (permalink)
New Member
 
Join Date: Oct 2009
Model: 7100T
PIN: N/A
Carrier: ATT
Posts: 5
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

In my experience that reply requires a bit of parsing. What I've come up with is instead of:
Code:
String result = (envelope.getResult()).toString();
use:

Code:
		SoapObject result = (SoapObject) ((SoapObject)envelope.getResponse()).getProperty(0);
 
		yourVarHere = hackToGetResponse("serviceToken", result.toString());
and hackToGetResponse gives you a parameter returned by your soap service:

Code:
public String hackToGetResponse(String key, String response) {
	System.out.println("hackToGetResponse:" + response);
	String start = "anyType{key=" + key + "; value=";
	String end = "; }";
 
	if (response.indexOf(start) == -1 ||
		response.indexOf(end) == -1) return "";
 
	System.out.println("hackToGetResponse:" + "response.substring(0, " + response.indexOf(start)  + ").substring(0, " + response.indexOf(end) + ");");
	response = response.substring(response.indexOf(start) + start.length());
	response = response.substring(0, response.indexOf(end));
 
	if (response.indexOf("anyType{}") != -1) return "";
 
	return response;
}
My soap service is PHP-based, so if you are using a different technology you may have to modify the parsing code somewhat. For giggles here is a server PHP code snippet:

Code:
 <?
require('../../../qcubed/wwwroot/includes/prepend.inc.php');
 
$server = new SoapServer(null, array('uri' => "urn:keyringlabs.com"));
$server->addFunction("login");
$server->handle();
 
function login($email, $pass) {
	if (strlen($email) == 0) {
		return Array('serviceToken' => '');
	} elseif (strlen($pass) == 0) {
		return Array('serviceToken' => '');
	} else {
		$objMerchant = Merchant::LoadByEmailPassword($email, $pass);
		if ($objMerchant == null || $objMerchant->Id < 1) {
			return Array('serviceToken' => '');
		} else {
			$key = uniqid();
			$objSess = new Merchantsessions();
			$objSess->MerchantID = $objMerchant->Id;
			$objSess->ServiceToken = $key;
			$objSess->Save();
		}
	}
 
	$result = Array('serviceToken' => $key);
	return $result;
}
 
 
?>
Offline  
Old 12-31-2009, 04:25 AM   #12 (permalink)
New Member
 
Join Date: Dec 2009
Model: 7100T
PIN: N/A
Carrier: Airtel
Posts: 5
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by nirmalsat View Post
Pls make ur question is clear.. Did u mean to say that it says cannot find module Ksoap2 preverified... If that is the case , its probably cos u ve not added the ksoap2.jar file properly.. Remove the folder and the jar and add it again.. Pls make sure that when u create the Lib folder , u add it to the project root.
Hi Nirmal,

I followed your steps and I got the following error. Please help me.

Regards,
krishnan
Offline  
Old 12-31-2009, 10:31 AM   #13 (permalink)
Knows Where the Search Button Is
 
Join Date: Aug 2009
Model: 8300
PIN: N/A
Carrier: Vodafone
Posts: 22
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Hi Nirmal,

I followed your steps and I got the following error. Please help me.
What error did u get??
Offline  
Old 02-08-2010, 01:18 PM   #14 (permalink)
New Member
 
Join Date: Feb 2010
Model: Bold
PIN: N/A
Carrier: Verizon
Posts: 2
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I've followed all the steps and I'm trying to launch my app now. I get the following error in the debug log that eclipse prints out -
Code:
Module 'HelloWorld' has verification errors.Error starting HelloWorld: Module 'HelloWorld' has verification errors.
and this in my blackberry simulator -
Code:
Error starting HelloWorld: Module ksoap2-j2me-core-prev-2.1.2' not found.
Any help is appreciated!

Teja

Edit:

I've just downloaded the core .jar file directly from sourceforge, preverified it and followed this process with my jar file. Now, I get an error that says

Quote:
Module 'ksoap2-j2me-core-2.1.2' not found.Error starting HelloWorld: Module 'ksoap2-j2me-core-2.1.2' not found.
Any help?

Last edited by tejaswiyvs : 02-08-2010 at 02:03 PM. Reason: (Got it working)
Offline  
Old 02-09-2010, 12:16 AM   #15 (permalink)
New Member
 
Join Date: Feb 2010
Model: Bold
PIN: N/A
Carrier: Verizon
Posts: 2
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by diego2k View Post
this works:

h tt p :/ /craigagreen.com/index.php?/Blog/blackberry-and-net-webservice-tutorial-part-1.html]craigAgreen - BlackBerry and .NET Web Service Tutorial - Part 1
Thank you! This is a life saver. If you can't get your own project to work, just download the sample workspace from this project, make eclipse point to this workspace and viola, everything will work.

Both preverified and Ksoap2 jar file not found errors will be solved by this.

Kudos
Offline  
Old 06-23-2010, 02:49 AM   #16 (permalink)
New Member
 
Join Date: May 2010
Model: 7100T
PIN: N/A
Carrier: 7100T
Posts: 2
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default having problem for "BlackBerry and .NET WebService Tutorial - Part 2"

how about "BlackBerry and .NET WebService Tutorial - Part 2"
(also in craigAgreen.com) , somebody get it successfully???
i having problem in this tutorial.....
can i know how to connect .net webservice(server) with blackberry simulator(client)?

someone can help me????

thanks^^
Offline  
Old 06-23-2010, 11:30 AM   #17 (permalink)
Knows Where the Search Button Is
 
Join Date: Aug 2009
Model: 8300
PIN: N/A
Carrier: Vodafone
Posts: 22
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

What do you mean by Part 2.. What are you exactly looking for , and what is the problem that you are facing with the current tutorial.
Offline  
Old 09-16-2010, 01:57 AM   #18 (permalink)
New Member
 
Join Date: Sep 2010
Model: 9550
PIN: N/A
Carrier: Airtel - India
Posts: 1
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

What can i put in these two.

SoapObject request = new SoapObject("urn:DEMO","DEMOMETHOD");
request.addProperty("PARAMETER_ID",id);
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.