我想用服务器中的 MS SQL 数据库表更新我设备中的本地 SQLite 数据库表(masters)。这里正在使用 SOAP 服务。如果在服务器中插入了任何新值,则单击按钮时,它必须同步并更新表中的新值。我想知道怎么做,下面是我用来调用网络服务的方法。
这里 MANUFACTURERID 和 MANUFACTURERDESC 是我要更新的两列。
我使用以下链接作为参考,并且使用了一个 TaskAsync.java 类。我想知道我必须在该类中编写什么来调用 Web 服务。作为java新手,请帮助我如何进行同步。提前感谢
http://stackoverflow.com/questions/14453577/sync-in-android-sqlite-and-sql-server-crud-operation-in-two-ways
**DATABASEHELPER.JAVA**
public void syncUsers(){
try{
String response = new **TaskAsync()**.execute("http://tempuri.org/ISave/SyncMaster").get();
Log.d("response",response);
String myPath = DB_PATH + DB_NAME;
String tablename = "ManufacturerDesc";
myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
myDataBase.delete(tablename, null, null);
ContentValues values = new ContentValues();
values.put("MANUFACTURERDESC",as_Manufacturer);
values.put("MANUFACTURERID", asManufactureId);
//values.put("MANUFACTURERID", value);
long status = myDataBase.insert(tablename, " ", values);
Log.d("database", Long.toString(status));
myDataBase.close();
}catch (Exception e){
e.printStackTrace();
}
}
**SOAPWebservice.java**
public SoapPrimitive manMaster(String manmas, String manmasid)
{
SoapPrimitive result = null;
try
{
SoapObject request = new SoapObject("http://tempuri.org/","SyncMaster");
request.addProperty("MANUFACTURERID", manmasid);//soap object
request.addProperty("MANUFACTURERDESC" , manmas);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
HttpTransportSE androidHttpTransport = new HttpTransportSE(url);
androidHttpTransport.call("http://tempuri.org/ISave/SyncMaster",envelope);
Log.e("WEB", androidHttpTransport.toString());
result = (SoapPrimitive)envelope.getResponse();
return result;
}
catch(Exception e){
Log.e("WebService","Error",e);
e.printStackTrace();
return null;
}
}