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