在黑莓中使用kso​​ap开发应用程序

时间:2012-01-10 14:40:26

标签: blackberry native ksoap2

我是黑莓开发的新手。我有任务使用Web服务开发应用程序来查找位置并将数据发送到服务器。

我为soap请求开发了以下代码,但是当我将它运行到我的手机时,没有任何事情发生。甚至数据也没有发送到服务器。请帮助我并提供一些有关此源代码的指南。

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);
        }
    }
} 

在上面的代码中,我接到ht.call的呼叫(soapAction,envelope);之后我没有收到服务器的任何回复。而且我也没有得到正确的方式来获得互联网访问和设备的其他访问权限。

所以请帮助我,并在肥皂信封的帮助下为我提供一些上传数据的步骤。

1 个答案:

答案 0 :(得分:0)

你可能想看一下ksoap2-android项目。它的代码仍然与Java 1.3 / Java ME兼容,并且应该可以在黑莓设备上正常工作..