0
我想用服務器中的MS SQL數據庫表更新我的設備中的本地SQLite數據庫表(主)。我在這裏使用SOAP服務。如果在服務器中插入任何新值,則單擊按鈕時,它必須同步並更新表中的新值。我想知道如何去做,下面是我用來調用Web服務的方法。更新在本地MS SQL SQL Server在本地更新SQLite數據庫表
這裏MANUFACTURERID和MANUFACTURERDESC是我想更新的兩列。
我用下面的鏈接作爲參考,並且有一個類TaskAsync.java使用。我想知道我必須在該課程中寫什麼來調用Web服務。作爲java的新手請幫助我如何做這個同步。 Thanx提前
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;
}
}
如何在上面的代碼 – Manju
定義setURL方法,它是用來設置Web方法的URL。它取決於你做出這個功能。 – Andrain