0
我是黑莓開發中的新手。我有任務使用Web服務開發應用程序來查找位置並將數據發送到服務器。使用黑莓中的ksoap開發應用程序
我開發了肥皂請求的以下代碼,但是當我將它運行到我的手機時,沒有任何事情發生。甚至數據也不會發送到服務器。請幫助我,併爲此源代碼提供一些指南。
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)的調用;之後,我沒有收到服務器的任何迴應。我也沒有得到適當的方式來授予互聯網訪問權限和其他設備訪問權限。
所以請幫助我,並提供一些步驟來上傳數據與肥皂信封的幫助。
oops。請在單獨的線程上執行網絡連接 – rfsk2010 2012-01-10 14:44:20
@ rfsk2010感謝您的回覆,請您解釋我的代碼中哪部分需要保存在單獨的線程中。 – 2012-01-11 04:42:49