Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
frankkona
Posts: 24
Registered: ‎10-01-2009
My Device: Not Specified

Blackberry how to call Coldfusion webservice with WSDL file

hello all,

I am trying to call a webservice from Blackberry JDE application. Following is the code and it is not working.

on ht.call function, it just sits there. not error though. I think action string is wrong. any ideas.

 public void initiateWebService()
    {
          
          String serviceUrl="http://www.mysite.com/WebServices.cfc/WSDL";
          String namespace="http://www.mysite.com/";
          String action="http://www.mysite.com/WebServices.cfc?method=fcnAccountsXMLGet"; ///??????????????do i need WSDL?
          String method="fcnAccountsXMLGet";

          try{
                      
                SoapObject client = new SoapObject(serviceUrl,method);
                //client.addProperty("num1","5");
                HttpTransport ht = new HttpTransport(serviceUrl);
                SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                envelope.bodyOut = client;
                envelope.dotNet = false; //I guess this has to be false since it is not dotnet
                
                try
                {
                    //ht.call("urn:aritmatikawsdl#add", envelope);
                    ht.call(action, envelope);
                    String response = envelope.getResponse().toString();
                }
                catch(Exception ex)
                {
                    ex.printStackTrace();
                }
            }catch(Exception e){
                e.printStackTrace();
            }

Please use plain text.
New Developer
DingusMcGee
Posts: 14
Registered: ‎04-15-2009
My Device: Not Specified

Re: Blackberry how to call Coldfusion webservice with WSDL file

I would strongly recommend getting Sun's Java Wireless Toolkit 2.5.2_01 for CLDC from their site (Sun JWT) and using the Stub Generator in the Utilities application to create the web service stubs that you can them import to your project. I've used this for a .NET WCF service and a .NET Web Service and both worked great.

 

The one thing you will need to consider is the method parameters and return types - they should be as standard as possible (you can use classes but their internal member variable data types should also be types that are supported). For supported types see below.

 

One thing i have found is that the stub generator won't generate stubs when the return type is a class that contains a member variable that is an instance of the same class - also, DateTime objects aren't always handled well so you probably want to return a string representation of your datetime in a pre-determined format. 

 

Sun web services for JME supported types

Please use plain text.
New Contributor
Medha07
Posts: 8
Registered: ‎01-05-2011
My Device: 8330

Re: Blackberry how to call Coldfusion webservice with WSDL file

Hi,

 

       Can you please provide steps or sample code for how to use Sun's Java Wireless Toolkit 2.5.2_01 for CLDC?

 

 

Thanks & Regards,

Medha

Please use plain text.
Developer
simon_hain
Posts: 15,806
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Blackberry how to call Coldfusion webservice with WSDL file

both ksoap2 and wtk have their advantages and disadvantages. personally i use ksoap2 for webservices. there are quite some tutorials and links, search the forum as i have posted them many times.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
New Contributor
Medha07
Posts: 8
Registered: ‎01-05-2011
My Device: 8330

Re: Blackberry how to call Coldfusion webservice with WSDL file

Hi Simon, I had already tried with ksoap. It works fine with .asmx service. But when I tried ksoap with WCF Service, it gives me the exception: org.xmlpull.v1.XmlPullParserException: unexpected type (position:END_DOCUMENT null@1:0 in java.io.InputStreamReader@44ebb7e0)

 

Is there any specific setting for consuming WCF service using ksoap?

 

Thanks & Regards,

Medha

Please use plain text.
Developer
simon_hain
Posts: 15,806
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Blackberry how to call Coldfusion webservice with WSDL file

most likely you get an http error message, ksoap2 cannot parse them. you can extend SocketConnectionMidp from the ksoap2 package to add connection status code handling etc. i have also extended it to give the full reply in plain text before parsing it. as a third tip, you can write most code in desktop java for jUnit by using HttpTransportSE from ksoap2, makes testing A LOT easier.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
New Contributor
Medha07
Posts: 8
Registered: ‎01-05-2011
My Device: 8330

Re: Blackberry how to call Coldfusion webservice with WSDL file

Can you please explain how to use ServiceConnectionMidp class to handle connection status code?

 

Thanks & Regards,

Medha

Please use plain text.
Developer
simon_hain
Posts: 15,806
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Blackberry how to call Coldfusion webservice with WSDL file

overwrite the openInputStream method of ServiceConnectionMidp, this is where the real connection happens. you can use getResponseCode on the connection there (use connector.open in the constructor).
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
New Contributor
Medha07
Posts: 8
Registered: ‎01-05-2011
My Device: 8330

Re: Blackberry how to call Coldfusion webservice with WSDL file

Hi Simon,

 

I have extended  class "ServiceConnectionMidp" and override the "openInputStream" method. But when I use:
int nLength = (int)connection.getLength(); OR  int nLength = oInputStream.available();
gives nLength  = 0.
I have also tried: IOUtilities.streamToBytes(oInputStream); But is is not working.

 

Thanks & Regards,

Medha

Please use plain text.
Developer
simon_hain
Posts: 15,806
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Blackberry how to call Coldfusion webservice with WSDL file

you don't have to retrieve anything, this is done by the kxml pull parser part of ksoap2. just call getResponseCode and handle the returned code (everything but 200 throws an exception with some descriptive text, for example).
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.