BlackBerry Forums Support Community

BlackBerry Forums Support Community (http://www.blackberryforums.com/index.php)
-   Developer Forum (http://www.blackberryforums.com/forumdisplay.php?f=15)
-   -   **** BlackBerry and Ksoap2 Tutorial ***** (http://www.blackberryforums.com/showthread.php?t=155972)

koic 06-19-2009 07:08 AM

Quote:

Originally Posted by joshi.rajnikant@gmail.com (Post 1392591)
can you please tell me what is this soapaction in this case.

Ok, here is one thought.
If you look into wsdl file you'll find tag 'soap:operation' with property 'soapAction'.
Basically, it's targetNamespace+'function name'.
Unfortunatly, in my case this did not help either, - I keep on getting this error:
org.xmlpull.v1.XmlPullParserException: unexpected type (position:TEXT Not authorized...
which is different from the one without soapAction:
org.xmlpull.v1.XmlPullParserException: attr value delimiter missing! (position:START_TAG <html dir='null'>
:-(
...
P.S. This is about preverification. In addition to what was said
you have to put jar.exe and jli.dll into the "...\BlackBerry JDE 4.7.0\bin\" folder.

koic 06-19-2009 10:42 AM

OK,
this thing works now.
Example is extremly simple 'though.
Service (ServiceHello.asmx.cs):
PHP Code:

xxx91;WebMethodxxx93;
public 
string HelloWorld()
{
       return 
"HelloWorld!";


Method to use it BlackBerry:
PHP Code:

String serviceNamespace "http://tempuri.org/";
String serviceAsmx "ServiceHello.asmx";
String serviceURL serviceNamespace serviceAsmx;
String serviceMethod "HelloWorld";
String soapAction serviceNamespace serviceMethod;
                            
HttpTransport ht = new HttpTransport(serviceURL);
ht.debug true;
                                
SoapObject request = new SoapObject(serviceNamespaceserviceMethod);

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.bodyOut request;
                        
ht.call(soapActionenvelope);
                                
String getRsp envelope.getResponse().toString(); 

Important things were (IMHO):
1. Use asmx file instead of wsdl in HttpTransport call.
Maybe because that was MS Web service (?)
2. To set soapAction.
3. Direct use of toString() instead of
PHP Code:

SoapObject result = (SoapObject)envelope.getResponse();
String getResp result.toString(); 

which caused (for me) that ClassCastException.

koic 06-19-2009 01:15 PM

P.S. To be able to pass parameters to (ASP.NET) web service this line must be added:
PHP Code:

envelope.dotNet true


koic 06-20-2009 08:03 AM

P.S.S. More notes related to KSoap2 usage.
1. Don't know how it is in Eclipse and others but with JDE (4.7)
I have to 'refresh' simulator as often as possible.
Otherwise that notorious error (XmlPullParserException: unexpected type) will be your best friend ;-) ,
even if you use soapAction and all this stuff I mentioned above.
To do this go File -> 'Erase simulator file' and then click all 3 of them. It does help!
2. Found this example very educational (y):
SourceForge.net: ksoap2 » Stadiums at the World Cup Example

isantos 06-23-2009 12:19 PM

hi...
I can connect to the webservice in my midlet, but to pass it on to the bb, I get a message saying that the application wants to connect to the internet ...
someone knows how to make this stop that message? apparently must be assigned permissions to the midlet .. but do not be like this :( :(
can someone help me?
thanks ..

PS: sorry for my English [google translation of Spanish-English: D]

in spanish :D:D
ya logre conectarme al webservice en mi midlet, pero al pasarlo a la bb me aparece un mensaje que dice que la aplicacion quiere conectarse a internet...
alguien sabe como hacer para que no aparezca ese mensaje??? al parecer hay que asignarle permisos al midlet.. pero no se como hacer eso :(:(
alguien puede ayudarme???
gracias..

nirmalsat 08-12-2009 11:26 PM

i am using the proper version of eclipse and like many people who have posted - i too am not able to see this- " Blackberry Project dependencies Tag".. Please help

monad.gon@gmail.com 11-19-2009 05:00 AM

to work the Ksoap in your BlackBerry project
 
Environment
-Eclipse Platform Version: 3.4.1, Build id: M20080911-1700
-BlackBerry JDE Componet Package 4.5.0

To work your Ksoap in BlackBerry.

1. download the ksaopXXX.jar file from here.
sourceforge.net/projects/ksoap2/
- you can download ksoap2-j2me-core-2.1.2.jar, 2009/11/19
- you can also rename the file
- if you want to use the attached file-Ksoap2.jar.txt-,please rename to Ksoap2.jar

2. save the jar file

3. in your eclipse, set the build path to your project.
your project -> Properties > Java Build Path > Libraries > Add External JARs
select the saved jar file
4. in your eclipse, set the jar file as an Export
Java Build Path > Order and Export
Just check in your ksoap jar file.

Good Luck!

monad.gon@gmail.com 11-19-2009 05:02 AM

to work the Ksoap in your BlackBerry project 2
 
2 Attachment(s)
There are images to set build path in your eclipse project.
images are related to #47.

devon_fritz 12-08-2009 07:43 PM

If you use the soap jar file, but want to distribute your app on App World, what do you do? I believe App World only lets you submit COD files.

anilarkay 12-18-2009 12:28 AM

Stuck on SOAP Application for BlackBerry
 
Hi All, I've successfully created a standalone java version of a SOAP communication class to enable Web Services data delegation.

But when I try to port to Blackberry device software, I'm having trouble.

1. I cannot find the correct replacement for H**pURLConnection class in Blackberry.

We need to use doOutput=true, so we can output the request/response to the Writer object through the stream.

right now, my coding goes like this:
==========================================
URL u = new URL(server);
URLConnection uc = u.openConnection();
H**pURLConnection connection = (H**pURLConnection) uc;
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("SOAPAction", SOAP_ACTION);
OutputStream out = connection.getOutputStream();
Writer wout = new OutputStreamWriter(out);
wout.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");

..................XML CODE HERE.................

wout.flush();
wout.close();

InputStream in = connection.getInputStream();
int c;
s="";
while ((c = in.read()) != -1)
{
//read and store the response as an XML String
}
in.close();

Can someone please look into this and suggest a solution with H**pTransport than using the H**pURLConnection? with H**pURLConnection, I am sending the SOAP request as an XML and getting the request as an XML. How can I do this with H**pTransport in KSOAPDemo version of the same, so I can get a simple SOAP Client working on blackberry device?

amramrhh 03-14-2010 06:04 AM

Please i need help
 
has any one solve error expected: START_TAG
my web service over server need windows credential????

niranjanvesikar 03-16-2010 05:08 AM

Problem in Ksoap
 
hey I mUsing ksoap2-j2me-core-prev-2.1.2.jar file in BB jde 5.0.0 it give me problem that SoapObject is null what should I do

can anybody help me please :-(

roshanthecho 03-17-2010 08:59 AM

I am trying to call my local web service (h**p://localhost:2715/Service1.asmx) created in .NET from BB application. I am using Eclipse 3.4.1 version. I have created library project and added the reference to the main project. While running in BB Simulator, it doesnot show any error message and also doesnot give the result of Web Method call.
While debugging, after displaying HelloWorld text and Service call button, it says "Source not found" with "Class File Editor" title and it also has a button "Change Attached Source...". What was the error? Please someone help me.

Here is my test code.

package com.fcs.sample;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope ;
import org.ksoap2.transport.HttpTransport;
import org.xmlpull.v1.XmlPullParserException;

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;

public class MyWebServiceTest extends UiApplication {
public static void main(String[] args) {
MyWebServiceTest theApp = new MyWebServiceTest();
theApp.enterEventDispatcher();
}

public MyWebServiceTest() {
pushScreen(new HelloWorldScreen());
}
}

final class HelloWorldScreen extends MainScreen {
private RichTextField textField;
private ButtonField srvButton = new ButtonField("Service Call");

public HelloWorldScreen() {
super();
System.out.println("Adding text");
LabelField title = new LabelField("HelloWorld Sample",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
setTitle(title);
textField = new RichTextField("Hello World!");
add(textField);
System.out.println("Added text");

srvButton.setChangeListener(listenerSrvButton);
add(srvButton);

}

FieldChangeListener listenerSrvButton = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
String serviceUrl = "h**p://localhost:2715/Service1.asmx";
String serviceNamespace = "h**p://tempuri.org/";
String soapAction = "h**p://tempuri.org/HelloWorld";
String serviceMethod = "HelloWorld";

HttpTransport ht = new HttpTransport(serviceUrl);
ht.debug = true;
ht.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");

SoapObject rpc = new SoapObject(serviceNamespace, serviceMethod);

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);

// envelope.setOutputSoapObject(rpc);

System.out.println("Created envelope");
envelope.bodyOut = rpc;
envelope.dotNet = true;
envelope.encodingStyle = SoapSerializationEnvelope.XSD;
/*
* envelope.encodingStyle = SoapSerializationEnvelope.ENC;
* envelope.encodingStyle = SoapSerializationEnvelope.XSI;
*/

// rpc.addProperty("Celsius", "12");
String result = "";
try {

ht.call(soapAction, envelope);
result = (envelope.getResponse()).toString();
System.out.println(result);// for debugging
net.rim.device.api.ui.component.Dialog.alert(envel ope
.getResponse().toString());

} catch (XmlPullParserException ex) {
String msg = ex.toString();
System.out.println(msg);
} catch (Exception ex) {
System.out.println("i am here in catch");
System.out.println(ex.getMessage());
// String msg = ex.toString();

}
textField.setText(result);
// ((HelloWorldScreen)this.getActiveScreen()).setScre enTest(result);
}
};

/*
* public void setScreenTest(String text) { textField.setText(text); }
*/

public boolean onClose() {
Dialog.alert("Goodbye!");
System.exit(0);
return true;
}
}

brooza 03-23-2010 08:15 AM

Ksoap2 tutorial with Eclipse plugin 1.1
 
Hi, has anyone tried the tutorial with BlackBerry Java Plug-in for Eclipse v1.1? I have Eclipse 3.5 and the 1.1. plugin with component pack 4.5?

Here is what I did:
1) New - Other - BlackBerry project - called Ksoap2, JRE: BB JRE 4.5 - Finish
2) In BB app descriptor window I have changed app type to Library and saved
3) right click on project - New - Folder - called lib
4) right click on folder - import - filesystem - jar provided in this tutorial
5) right click on project - properties - java build path: a) tab source - add folder - check Ksoap2/lib b) tab Libraries - add jars.. - Ksoap2/lib/the jar file c) tab Order and Export - check the jar file ok

And now the testing project:
1) New - Other - BlackBerry project - called Ksoap2Test, JRE: BB JRE 4.5 - Finish
2) right click on Ksoap2Test - properties - Java build path: a) tab Projects - check Ksoap2 b) tab Libraries - add Ksoap2/bin/the jar file c) tab Order and export - check the jar and project Ksoap2
3) right click on KsoapTest - new - class: called Ksoap2Demo, package mypackage - Finish
4) Copy the source code of java file provided in tutorial, change the mistakes in name of classes (StockQuoteDemo>Ksoap2Demo and StockQuoteScreen>Ksoap2DemoScreen), check the package and save
5) Run - Run as - BB simulator


Until running the project, everything seems to be fine but unfortunatelly the app doesnt run, just simulator without the app. In eclipse console I have found this:
Packaging project Ksoap2
C:\Program Files\Eclipse\plugins\net.rim.ejde.componentpack4. 5.0_4.5.0.21\components\bin\rapc.exe -quiet library=deliverables\4.5.0\Ksoap2 deliverables\4.5.0\Ksoap2.rapc -sourceroot=C:\Users\JB.s4u\workspace\Ksoap2\src;C: \Users\JB.s4u\workspace\Ksoap2\lib;C:\Users\JB.s4u \workspace\Ksoap2\res -import=C:\Program Files\eclipse\plugins\net.rim.ejde.componentpack4. 5.0_4.5.0.21\components\lib\net_rim_api.jar;C:\Use rs\JB.s4u\workspace\Ksoap2\lib\ksoap2-j2me-core-prev-2.1.2.jar C:\Users\JB.s4u\workspace\Ksoap2\bin
JAR file creation failed with error -1
The preverified classes if any are in tmp8965. See jar log of errors in C:\Users\JB.s4u\AppData\Local\Temp\rapc_191cb4a2.d ir\jarlog.txt
Error!: Error: preverifier failed: C:\Program Files\Eclipse\plugins\net.rim.ejde.componentpack4. 5.0_4.5.0.21\components\bin\preverify.ex ...
Packaging project Ksoap2 failed (took 0.464 seconds)

Packaging project Ksoap2Test
C:\Program Files\Eclipse\plugins\net.rim.ejde.componentpack4. 5.0_4.5.0.21\components\bin\rapc.exe -quiet codename=deliverables\4.5.0\Ksoap2Test deliverables\4.5.0\Ksoap2Test.rapc -sourceroot=C:\Users\JB.s4u\workspace\Ksoap2Test\sr c;C:\Users\JB.s4u\workspace\Ksoap2Test\res -import=C:\Program Files\eclipse\plugins\net.rim.ejde.componentpack4. 5.0_4.5.0.21\components\lib\net_rim_api.jar;C:\Use rs\JB.s4u\workspace\Ksoap2\bin\ksoap2-j2me-core-prev-2.1.2.jar;..\Ksoap2\deliverables\4.5.0\Ksoap2.jar C:\Users\JB.s4u\workspace\Ksoap2Test\bin
I/O Error: Import file not found: ..\Ksoap2\deliverables\4.5.0\Ksoap2.jar
Packaging project Ksoap2Test failed (took 0.967 seconds)


I do not understand what does the error report say. Could anyone give me a tip where the problem might be or can you try my steps to resolve if this is general or just my configuration problem.
Thank you very much.

baskar 04-29-2010 01:24 AM

Ksoap Configuration
 
Hi,

- I am downloaded files from first posted links. but ksoap.jar not contain.
- How to integrate ksoap.jar.
- Please help anybody.

Thanks.

baskar 04-30-2010 02:24 AM

Hi,

Please help any one for ksoap.
i have one error
-data handling errorSoapFault - faultcode: 'soap:Client' faultstring: 'Server did not recognize the value of HTTP Header SOAPAction: VerifyUser.'
faultactor: 'null' detail: org.kxml2.kdom.Node@1b731777

Thanks.

aka47 05-21-2010 05:54 AM

im having foolowing exception: XML PARSER EXCEPTION

aka47 05-25-2010 12:06 AM

XML PARSER EXCEPTION

Can AnyBody help?

swati 06-29-2010 04:54 AM

1) Is it compultion to start MDS when we consume web service in eclipse BB and run it???( because my MDS is not working it open and closed automaticaly)

2) When i try to run below code in eclipse and when i put pointer on liabrary code then it gives error "source is not attached n javadoc" and some datagram error

Ruchijain 08-17-2010 12:12 AM

Re:XML pull parser exception
 
I encountered the same problem
but after correcting the port number of tomcat server,my problem was resolved so check the port number in use of tomcat in wsdl of ksoap web service and in your blackberry code


All times are GMT -5. The time now is 11:01 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.