Search code examples
blackberrynativeksoap2

Develop application using ksoap in blackberry


i am new in blackberry development. and i have task to develop the application using web service to find the location and send the data to the server.

I have developed the following code for the soap request but when i run it to my mobile nothing is happening. and even data is also not sending to the server. Please help me and provide some guide to for this source code.

final class MyScreen extends SplashScreen  {

    private String serviceUrl = "myurl/GPStracker.asmx";
    private String serviceNamespace = "http://tempuri.org/";
    private String soapAction = "http://tempuri.org/GPSUnikeylogin";
    private String methodName = "GPSUnikeylogin";

    private String imei = GPRSInfo.imeiToString(GPRSInfo.getIMEI(), false);

    private BasicEditField roundedBorderEdit = null;
    private ButtonField bf;
    private String responseBody;
    Hashtable persistentHashtable; 
    PersistentObject persistentObject;
    static final long KEY = 0x9df9f961bc6d6baL;

    public MyScreen(Bitmap popup, int seconds) {
            super(Bitmap.getBitmapResource("bg.png"), 5);

                //persistentObject = PersistentStore.getPersistentObject(KEY);
                 roundedBorderEdit = new BasicEditField();
                 roundedBorderEdit = new BasicEditField("","",50,EditField.EDITABLE | EditField.FILTER_NUMERIC | EditField.FIELD_HCENTER) {
                     public void paint(Graphics g) {
                         super.paint(g);
                         g.drawRect(0, 0, getWidth(), getHeight());
                     }
                 };
                 add(roundedBorderEdit);

                 bf = new ButtonField ("Register", Field.FOCUSABLE);
                 bf.setChangeListener(new FieldChangeListener(){
                     public void fieldChanged(Field field, int context) {

                         callWebService();

                     }
                 });
                 add (bf);

    }   
    private void callWebService()
    {
        String e =  "123";//MyScreen.this.roundedBorderEdit.getText();
        //Dialog.alert(e.toString());

        SoapObject rpc = new SoapObject(serviceNamespace, methodName);
        //Dialog.alert(rpc.toString());

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

        rpc.addProperty("vUnikey",e.toString());
        rpc.addProperty("vImei_No",imei.toString());

        //Dialog.alert(rpc.toString());
        envelope.setOutputSoapObject(rpc);
        envelope.bodyOut = rpc;
        envelope.dotNet = true;
        envelope.encodingStyle = SoapSerializationEnvelope.XSI;

        HttpTransport ht = new HttpTransport(serviceUrl);//+ ";deviceside=true;apn=blackberry.net");

        Dialog.alert(ht.toString());

        //HttpTransport ht = new HttpTransport(serviceUrl);
        ht.debug = true;
        ht.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        //Dialog.alert("set to xml");
        String result= null;

        try{

            ht.call(soapAction, envelope);
            Dialog.alert(ht.toString());
            result = (envelope.toString());
            Dialog.alert(result.toString());
        }

        catch (org.xmlpull.v1.XmlPullParserException ex2) {
        }

        catch (Exception ex) {
             String bah = ex.toString();
             System.out.println(bah);
        }
    }
} 

In the above code i am getting the call till ht.call(soapAction, envelope); after that i am not getting any response from the server. and i also not get the proper way to give the permission for the internet access and other access from the device.

So please help me and provide me some step to upload data with the help of soap envelope.


Solution

  • You might want to look at the ksoap2-android project. Its code is still Java 1.3/Java ME compatible and should work just fine on blackberry devices..