BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 08-18-2010, 01:03 AM   #1 (permalink)
New Member
 
Join Date: Aug 2010
Model: 9000
PIN: N/A
Carrier: Idea
Posts: 2
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Invoke webservice in bb java application

Please Login to Remove!

Hi
i m new to bb development. i have written a small application in java and now i want to invoke a webservice on the click of a button. i have created the wsdl file but now i am not sure how to read it from my app.

Can anyone plz help and guide me the steps or sample code to call a webservice and display the result in screen. I also came across something like KSOAP2 please tell me is this the only way to call webservice.

I am using JDE4.6

thanks
bansi
Offline  
Old 08-18-2010, 06:20 AM   #2 (permalink)
Appleinator
 
Dubdub's Avatar
 
Join Date: Nov 2005
Location: New Hampshire
Model: App6+
OS: AJBR549
PIN: Ask
Carrier: ATT & Verizon
Posts: 20,038
Post Thanks: 52
Thanked 777 Times in 737 Posts
Default

Moved to a more appropriate section.
__________________
-->>BB FAQ

-->>Stinsonddog's Tip Site!

-->>Twitter


If someone helps, tell them by clicking the Thanks button.!!
Offline  
Old 08-18-2010, 08:02 AM   #3 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

**** BlackBerry and Ksoap2 Tutorial *****
Offline  
Old 08-24-2010, 02:24 PM   #4 (permalink)
New Member
 
Join Date: Aug 2010
Model: 9700
PIN: N/A
Carrier: stc
Posts: 1
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

have you do your application ?
I have the same issue now if you still work tell me so we can share knowledge info and hopefully great final applications
Offline  
Old 08-27-2010, 03:10 AM   #5 (permalink)
New Member
 
Join Date: Aug 2010
Model: 9000
PIN: N/A
Carrier: Idea
Posts: 2
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

I am still working on this web service part. What i figured out is there are two ways to achieve this.
1) use KSOAP2
2) using JSR172 api

I am working with JSR172 and for that i have created a WSDL file using Axis2 in eclipse and also generated the stub client using wireless toolkit but now when i am invoking that client in my BB code it is giving me JAXRPC Exception.
I dont know why it is giving me that exception.

Anybody who can help me regarding this exception will be a great help or atleast let me know where i am doing wrong

Thanks
Bansi
Offline  
Old 08-31-2010, 09:57 AM   #6 (permalink)
Knows Where the Search Button Is
 
Join Date: Jun 2010
Model: 8530
PIN: N/A
Carrier: Sprint
Posts: 48
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

While generating the stubs using wireless toolkit, it generates one file "YourWebServiceNameSoap_Stub.java". Inside that file, please check whether there is correct webservice URL path or not. Is that webservice running or not?

_propertyValues = new Object[] {"http://......................./webservice.asmx"};
Offline  
Old 08-31-2010, 10:00 AM   #7 (permalink)
Knows Where the Search Button Is
 
Join Date: Jun 2010
Model: 8530
PIN: N/A
Carrier: Sprint
Posts: 48
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Also please see this if you want to use KSOAP
Code:
//passing strings and returns EmployeeResponse object
FieldChangeListener employeeListener = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
String serviceUrl = "http : //servername/service1.asmx";
String serviceNamespace = "http : //tempuri.org/";
String soapAction = "http : //tempuri.org/GetEmployeeDetail";

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

rpc.addProperty("EmployeeID", "123");
rpc.addProperty("EmployeeName", "MyName");

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.bodyOut = rpc;
envelope.dotNet = true; 
envelope.encodingStyle = SoapSerializationEnvelope.XSD;
envelope.addMapping("http : //tempuri.org/encodedTypes",
"EmployeeResponse", new EmployeeResponse().getClass());

envelope.setOutputSoapObject(rpc);

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

try {
ht.call(soapAction, envelope);
EmployeeResponse myObj = (EmployeeResponse) envelope.getResponse();
add(new RichTextField("ID: " + myObj.EmpID + "\n" + "Name: "+ myObj.EmpName + "\n" + "Phone: " + myObj.Phone + "\n"+ "Address: " + myObj.Address));
} 
catch (Exception ex) {
String msg = ex.toString();
System.out.println(msg);
add(new RichTextField("Error Message: " + msg));
}
}
};

Last edited by romah : 08-31-2010 at 10:02 AM.
Offline  




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