BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 08-11-2008, 03:33 PM   #1 (permalink)
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Access java web service via ksoap2

Please Login to Remove!

Hi,

I have accessed a .Net web service using Http Request (via url) and that was pretty much easy. Now I need to access a java web service. I am not sure if I can use if via URL as I am not able to do that till now. Another option is to use ksoap2. Any idea about how can I proceed with that. I just need a good tutorial of information source as i am not able to find something relevant...

All I can find is accessing .Net web service via Http Client.

Hope to hear something great!!!
__________________
Smart People ask for Help!!!
Offline  
Old 08-12-2008, 08:57 AM   #2 (permalink)
New Member
 
Join Date: Aug 2008
Model: 9000
PIN: N/A
Carrier: Rogers
Posts: 1
Post Thanks: 0
Thanked 0 Times in 0 Posts
Angry Accessing .net service via http...

Quote:
Originally Posted by baran_khan View Post
Hi,

I have accessed a .Net web service using Http Request (via url) and that was pretty much easy. Now I need to access a java web service. I am not sure if I can use if via URL as I am not able to do that till now. Another option is to use ksoap2. Any idea about how can I proceed with that. I just need a good tutorial of information source as i am not able to find something relevant...

All I can find is accessing .Net web service via Http Client.

Hope to hear something great!!!

Hi baran_khan,

i see that you have accessed a .net web service using http request from your blackberry... could you please show me an example as to how exactly you did that. i have been trying to access a .net web service from my BB application which i have developed using blackberry JDE. so far i keep getting the error authentication required. my web service is in our corporate intranet.
Offline  
Old 08-12-2008, 02:03 PM   #3 (permalink)
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Its pretty straight forward....

First create class ConnectionThread.java and paste the following code in it..

PHP Code:
import java.io.IOException;
import java.io.OutputStream;
import java.io.InputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;

public class 
ConnectionThread extends Thread {
    private 
boolean start false;
    private 
boolean stop false;
    private 
String url;
    private 
String data;
    public 
int status=0;
    public 
boolean sendResult false;
    public 
boolean sending false;
    private 
String requestMode HttpConnection.POST;
    public 
String responseContent;
    public 
void run() {
        while (
true) {
            if (
start == false && stop == false) {
                try {
                    
sleep(200);
                } catch (
InterruptedException e) {
                    
e.printStackTrace();
                }
            } else if (
stop) {
                return;
            } else if (
start) {
                
http();
            }
        }
    }
    
    private 
void getResponseContentHttpConnection conn throws IOException {
        
InputStream is null;
        
is conn.openInputStream();
        
// Get the length and process the data
        
int len = (int) conn.getLength();
        if ( 
len ) {
            
int actual 0;
            
int bytesread 0;
            
bytexxx91;xxx93; data = new bytexxx91;lenxxx93;;
            while ( ( 
bytesread != len ) && ( actual != -) ) {
                
actual is.readdatabytesreadlen bytesread );
                
bytesread += actual;
            }
            
responseContent = new String (data);
        } else {
            
int ch;
            while ( ( 
ch is.read() ) != -) {

            }
        }
    }
    
    private 
void http() {
        
HttpConnection conn null;
        
OutputStream out null;
        
int responseCode;
        try {
            
conn = (HttpConnectionConnector.open(url);
            
conn.setRequestMethod(requestMode);
            
out conn.openOutputStream();
            
out.write(data.getBytes());
            
out.flush();
            
responseCode conn.getResponseCode();
            
status responseCode;
            if (
responseCode != HttpConnection.HTTP_OK) {
                
sendResult false;
                
responseContent null;
            } else {
                
//status = 1;
                
sendResult true;
                
getResponseContentconn );
            }
            
start false;
            
sending false;

        } catch (
IOException e) {
            
start false;
            
sendResult false;
            
sending false;
        } 
    }

    public 
void get(String url) {
        
this.url url;
        
this.data "";
        
requestMode HttpConnection.GET;
        
sendResult false;
        
sending true;
        
start true;
    }
    
    public 
void post(String urlString data) {
        
this.url url;
        
this.data data;
        
requestMode HttpConnection.POST;
        
sendResult false;
        
sending true;
        
start true;
    }

    public 
void stop() {
        
stop true;
    }


Now in the class where you need to access the web service follow following code...

PHP Code:
connThread = new ConnectionThread();
        
connThread.start();
        
connThread.get("http://localhost:8080/ServiceReminder/services/Reminders/Login?username="+uname+"&password="+pwd);
      while (
connThread.sending) {
            try {
                
Status.showsb.append(".").toString() );
                
//Bitmap bmp = Bitmap.getBitmapResource("resources/mcustodial_logo.jpg");
                //Status.show(sb.append(".").toString(),bmp,1);
                
Thread.sleep(100);
            } catch (
InterruptedException e) {
                
e.printStackTrace();
            }
        }

        if (
connThread.sendResult) {
            
Status.show("Transmission Successful");
            
String str connThread.responseContent
this is as simple as anything...god knows why I am stuck with this java thing..anyways hope you find it helpful....
__________________
Smart People ask for Help!!!
Offline  
Old 08-13-2008, 04:05 AM   #4 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi I use java web service and ksoap2.

So if you have any question, I will answer you as clearly as possible.

But first tell me where you are for the moment
Offline  
Old 08-13-2008, 04:59 AM   #5 (permalink)
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by goulamass View Post
Hi I use java web service and ksoap2.

So if you have any question, I will answer you as clearly as possible.

But first tell me where you are for the moment
HI,

Thanks for the reply, As I have already posted some code, I am familiar with accessing the web service built in .Net. I am fairly new to ksoap2 and have already tried my hand on it.

My few questions are:

1. Where can I get the preverified jar file for ksoap2. I downloaded this preverified jar from internet but for some reason it was giving error with org.ksoap.serialization package.

2. Secondly, if you can provide me with some sample that can give me an idea about how to approach it as presently I am not going anywhere with the things....

I am pretty much sure I am making a very small mistake ...thats what I usually do as major issues are easy to sort out...

Hope to hear from you soon...
__________________
Smart People ask for Help!!!
Offline  
Old 08-14-2008, 03:34 AM   #6 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

First for the ksoap you just need the core and not the full version wich generate error when it's preverified.

And for the sample no problem

You have to build your object using the soapObject structure and send them with the enveloppe.
Code:
SoapObject request = new SoapObject(null, null);
request.addProperty(namespace, "PIN", DeviceInfoHelper.PIN);
request.addProperty(namespace, "ServiceId", String.valueOf(serviceId));
request.addProperty(namespace, "Text", text);
request.addProperty(namespace, "Details", new Boolean(details));

SoapObject bodySoap = new SoapObject(MethodNamespace, MethodName);
bodySoap.addProperty("request", request)

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

envelope.bodyOut = bodySoap;


ht = new HttpTransport(url);
ht.call(MethodAction, envelope);
result = (SoapObject) envelope.getResponse();
Offline  
Old 08-15-2008, 10:54 AM   #7 (permalink)
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi, thanks again for the reply, what about the preverified ksoap jar file...any chance you can send me that...I have already done this part but because the jar is not preverified, its giving the error. I have the core version of ksoap2
__________________
Smart People ask for Help!!!
Offline  
Old 08-16-2008, 11:09 PM   #8 (permalink)
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have preverified the ksoap2.jar file using following command:


C:\Program Files\Research In Motion\BlackBerry JDE 4.0\bin>preverify -classpath "C:\Program Files\Research In Motion\BlackBerry JDE 4.0\lib\net_rim_api.jar" "D:\RIMClient\Standard\lib\kxmlrpc_full.jar"

Once done that I have tried importing the org.ksoap2.* package but it still give the error...package does not exist.

Any idea bout it...I have everything I can but without any thing positive
__________________
Smart People ask for Help!!!
Offline  
Old 08-18-2008, 06:21 AM   #9 (permalink)
Knows Where the Search Button Is
 
Join Date: Nov 2007
Model: 8800
PIN: N/A
Carrier: o2
Posts: 25
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

have you added the ksoap as a library project and made your main project dependant on it?
Offline  
Old 08-18-2008, 06:58 AM   #10 (permalink)
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by alzzz View Post
have you added the ksoap as a library project and made your main project dependant on it?
Hey alzzz, thanks for ur help mate....I fixed this issue but didnt updated the status on the forum...thanks again for the help
__________________
Smart People ask for Help!!!

Last edited by baran_khan : 08-18-2008 at 07:07 AM.
Offline  
Old 10-17-2008, 02:14 PM   #11 (permalink)
New Member
 
Join Date: Oct 2008
Model: Bold
PIN: N/A
Carrier: Sprint
Posts: 3
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I just tried the code that baran_khan posted, but without success. Running in debug mode on the simulator the process simply stops during the http() method after it executes the line:

out.write(data.getBytes());

Any ideas why this might be happening?
Offline  
Old 10-17-2008, 04:56 PM   #12 (permalink)
New Member
 
Join Date: Oct 2008
Model: 8100
PIN: N/A
Carrier: TELCEL
Posts: 11
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Preverified ksoap

Hi,

I have this preverified ksoap2, I have the same problems with the ksoap from the oficial page. I got this file from the forum, but I cannot find the original post.

Hope it helps

Regards!

PD: rename .txt to .jar
Attached Files
File Type: txt ksoap2-j2me-core-2.1.2.txt (45.1 KB, 146 views)

Last edited by ArthurKnight : 10-17-2008 at 05:06 PM.
Offline  
Old 10-18-2008, 02:44 AM   #13 (permalink)
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by kevinhaines View Post
I just tried the code that baran_khan posted, but without success. Running in debug mode on the simulator the process simply stops during the http() method after it executes the line:

out.write(data.getBytes());

Any ideas why this might be happening?
Make sure you are not using localhost for the IP address, that will be the blackberry emulator itself by default. you need the IP address of the system you got your web service on.

By the looks of the thing you mentioned, I guess your app is not able to find the destination to contact with.
__________________
Smart People ask for Help!!!
Offline  
Old 10-18-2008, 02:44 AM   #14 (permalink)
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by ArthurKnight View Post
Hi,

I have this preverified ksoap2, I have the same problems with the ksoap from the oficial page. I got this file from the forum, but I cannot find the original post.

Hope it helps

Regards!

PD: rename .txt to .jar
Can you further elaborate the issue so that I can try helping
__________________
Smart People ask for Help!!!
Offline  
Old 12-19-2008, 05:01 AM   #15 (permalink)
tnk
New Member
 
Join Date: Nov 2008
Model: 7100T
PIN: N/A
Carrier: fdgd
Posts: 1
Post Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy Problem in using Ksoap2 in my blackberry java application

I used Ksoap2 jar(ksoap2-j2me-core-2.1.2) in my project. I added this jar through a library project in my CLDC Application.

But when I try to debug the application on simulator, on launching the application error occured " Module Ksoap2 (jar file name) not found".

Can anybody help me......

Basically I am stuck with how to access .net web service having user defined type as formal parameters, in my application, I used httpconnection with soapheader but still nt able to access web service.

Please reply as early as possible.....
Offline  
Old 12-19-2008, 06:00 AM   #16 (permalink)
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by tnk View Post
I used Ksoap2 jar(ksoap2-j2me-core-2.1.2) in my project. I added this jar through a library project in my CLDC Application.

But when I try to debug the application on simulator, on launching the application error occured " Module Ksoap2 (jar file name) not found".

Can anybody help me......

Basically I am stuck with how to access .net web service having user defined type as formal parameters, in my application, I used httpconnection with soapheader but still nt able to access web service.

Please reply as early as possible.....
Hi,

Along with adding the jar as a library project, you need to add it as a reference as well. I.e. in the project itself add this file as an external reference. The ksoap2.jar is supposed to be added twice, one via reference and second via library project.

also please make sure that you have preverified version of ksoap2 jar.
__________________
Smart People ask for Help!!!
Offline  
Old 02-19-2009, 09:23 AM   #17 (permalink)
New Member
 
Join Date: Feb 2009
Model: Storm
PIN: N/A
Carrier: T-Mobile
Posts: 1
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by goulamass View Post
First for the ksoap you just need the core and not the full version wich generate error when it's preverified.

And for the sample no problem

You have to build your object using the soapObject structure and send them with the enveloppe.
Code:
SoapObject request = new SoapObject(null, null);
request.addProperty(namespace, "PIN", DeviceInfoHelper.PIN);
request.addProperty(namespace, "ServiceId", String.valueOf(serviceId));
request.addProperty(namespace, "Text", text);
request.addProperty(namespace, "Details", new Boolean(details));

SoapObject bodySoap = new SoapObject(MethodNamespace, MethodName);
bodySoap.addProperty("request", request)

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

envelope.bodyOut = bodySoap;


ht = new HttpTransport(url);
ht.call(MethodAction, envelope);
result = (SoapObject) envelope.getResponse();
When you use the call method what do you mean by MethodAction?
Offline  
Old 06-01-2009, 07:54 AM   #18 (permalink)
Knows Where the Search Button Is
 
Join Date: Jul 2008
Location: India
Model: 9000
Carrier: AirTel
Posts: 29
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default How can I acces PHP wbservice from my Blackberry Application?

Pleas help he ... Here is a web service in php for sending email with attachments. How can I acces that webservice from my Blackberry phone. I am creating an Application which is using that php webservice for sending the mails.
__________________
Praveen K
Offline  
Old 06-02-2009, 10:20 AM   #19 (permalink)
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

You got multiple options for doing that.

First, you can use connectionmanager class for that.

Second, The KSOAP library.

please be very specific about what exactly you are looking for. Presently it is difficult for me to understand what you are looking for. Have you tried anything or are looking for clues.
__________________
Smart People ask for Help!!!
Offline  
Old 08-25-2009, 03:01 AM   #20 (permalink)
New Member
 
Join Date: Jul 2009
Model: 7100T
PIN: N/A
Carrier: Airtel
Posts: 1
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Baran,
I assume that you've had a good experiece with BB development so far. I'm a dotnet developer new to Java and have been assigned to task to develop a BB Java project on my own.
I've chosen KSoap2 ( or should I choose KSoap1 ? ) so far because my project requries allowing the end user to customize which web service URL to call. Since JSR172 uses static stubs this is not possible there.
I'm pasting the code for a sample HelloWorld webservice call I have written using KSoap2. (I've followed your steps to add the ksoap jar to my lib)
However, once the control reaches the ksoap_HelloWorld constructor it goes to NoSuchFile.java error page. Any idea what could be going wrong ?
Code:

public class ksoap_HelloWorld extends MIDlet implements CommandListener {

private Form mainForm;
private TextField symbolField;
private StringItem resultItem;
private Command getCommand;


public ksoap_HelloWorld () {
try
{

symbolField = new TextField ("Symbol", "IBM", 5, TextField.ANY);
resultItem = new StringItem ("", "");
getCommand = new Command ("Get", Command.SCREEN, 1);
mainForm.append (symbolField);
mainForm.append (resultItem);
mainForm.addCommand (getCommand);
mainForm.setCommandListener (this);
}
catch(Exception e)
{
e.printStackTrace ();
resultItem.setLabel ("Error:");
resultItem.setText (e.toString ());
}

}

public void startApp () {
mainForm = new Form ("HelloWorld");
Display.getDisplay (this).setCurrent (mainForm);
}

public void pauseApp () {
}

public void destroyApp (boolean unconditional) {
}

public void commandAction (Command c, Displayable d) {
try {
String symbol = symbolField.getString ();
resultItem.setLabel (symbol);

// set up the variables
String endPointURL = new String("[Web Service URL]");
String nameSpace = new String("[http//hello]");
String soapAction = new String("[http//hello]");
String urn = new String("urn:SAPService");

// create the envelope
SoapObject soap = new SoapObject(urn, "HelloWorld");
soap.addProperty("name", symbol);

// serialize the envelope
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.bodyOut = soap;

// set up the transport
HttpTransport ht = new HttpTransport(endPointURL);

//make the call
ht.call("", envelope);

//get the response
Object soapIn = envelope.getResponse();
// Do something with the response
//outputForm.append("kSOAP response: " + soapIn.toString());
//display.setCurrent(outputForm);
resultItem.setText("kSOAP response: " + soapIn.toString());

}
catch (Exception e) {
e.printStackTrace ();
resultItem.setLabel ("Error:");
resultItem.setText (e.toString ());
}
}

/** for me4se */

public static void main (String [] argv) {
ksoap_HelloWorld k1 = new ksoap_HelloWorld ();
k1.startApp();
//new ksoap_HelloWorld ().startApp ();
}
}


Looking forward to your help,
Thanks a lot in advance!!

Manhar.
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.