【问题标题】:Develop application using ksoap in blackberry在黑莓中使用 ksoap 开发应用程序
【发布时间】:2012-01-17 14:45:59
【问题描述】:

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

我已经为肥皂请求开发了以下代码,但是当我将它运行到我的手机时,什么都没有发生。甚至数据也没有发送到服务器。请帮助我并为此源代码提供一些指导。

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);之后我没有得到服务器的任何响应。而且我也没有获得正确的方法来授予从设备访问互联网和其他访问权限。

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

【问题讨论】:

  • 哎呀。请在单独的线程上进行网络连接
  • @rfsk2010 感谢您的回复,请您解释一下我的代码的哪一部分需要保留在单独的线程中。

标签: blackberry native ksoap2


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-01
    • 2012-06-26
    相关资源
    最近更新 更多