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
Posts: 20
Registered: ‎06-08-2009
My Device: Not Specified

Web service connection

[ Edited ]

hello


I am developing an application that consumes a Web Service, use HttpConnection Connector.open () and send the parameters through the model "GET", but the connexion is broken very easily, it is best to use ksoap or is there some other suggestions to make this? this is a bit of code to determine when the connection is broken,

 

 

public static InputStream SetConnection(String url){

 

        HttpConnection conn = null;        

        int responseCode;

        InputStream is = null;               

        try{                                                                                                                 

                conn = (HttpConnection) Connector.open(url+";deviceside=true");                

                conn.setRequestMethod(HttpConnection.GET);                                               

                responseCode = conn.getResponseCode();                

                if (responseCode != HttpConnection.HTTP_OK) {                      

                    is = null;

                }else {                                       

                    is = conn.openInputStream();

                }                          

         } catch(Exception ex){             

         }         

         return is;

    }

 

InputStream is = SetConnection("http://sales........./UserValidate?_user=" + _responseUser + "&_password=" + _responsePassword);            

  if(is == null)  

 {

       Application.getApplication().invokeLater(new Runnable() {

                    public void run(){  

                                    Dialog.alert(" conexion ERROR");                  

                    }

               } );

         } else   

              Application.getApplication().invokeLater(new Runnable() {

                    public void run(){  

                                    Dialog.alert("conexion OK");                  

                    }

               } );

 }


Thanks

Regular Contributor
Posts: 67
Registered: ‎08-16-2011
My Device: 7185
My Carrier: Reliance

Re: Web service connection

ksoap is best Smiley Happy

 

i did its work very good but i am having problem in authentication only if your web service does not require http basic authentication then ksop is very good

 

Smiley Happy

 

Developer
Posts: 16,932
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Web service connection

ksoap2 works pretty good for most webservices and has some advantages over stubs, but it is more difficult to set up than stubs.
you can find some resources for both by doing a search on the forum.

basic auth also works with ksoap2.
----------------------------------------------------------
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
Contributor
Posts: 21
Registered: ‎02-21-2012
My Device: Blackberry 8520
My Carrier: T-Mobile

: Web service connection

public

String ServiceConnect(){

 

String response=

"";

 

String serviceUrl=

"http://www.webservicex.net/stockquote.asmx;deviceside=true";//interface=wifi";

 

String serviceNamespace =

"http://www.webserviceX.NET/";

String soapAction =

"http://www.webserviceX.NET/GetQuote";

 

 

SoapObject rpc =

new SoapObject(serviceNamespace,"GetQuote");

rpc.addProperty(

"symbol","INFY");

 

SoapSerializationEnvelope envelope =

new SoapSerializationEnvelope(SoapEnvelope.VER11);

envelope.

bodyOut= rpc;

envelope.

dotNet = true;

 

HttpTransport ht =

newHttpTransport(serviceUrl);

ht.

debug = true;

 

try

{

ht.call(soapAction,envelope);

 

response = (envelope.getResponse()).toString();

 

 

}

catch(Exception ex)

{

response = ex.toString();

 

 

}

// add(new EditField("RESULT:",response));returnresponse;

}

Highlighted
Contributor
Posts: 21
Registered: ‎02-21-2012
My Device: Blackberry 8520
My Carrier: T-Mobile

Re: : Web service connection

proper working code