2014-10-07 37 views
0

我正在一個android應用程序,它有點像一個窗體。它目前的工作原理是用戶輸入的數據被解析爲json到php腳本並存儲在數據庫中。我聽說這不是最好的方式,而且我需要使用webservice/web API來代替服務器,因爲它更安全。我的問題是,我真的需要使用webservice/API來發送數據嗎?如果我這樣做,你能指導我進一步學習如何創造這個機會嗎?我需要一個web服務或一個web api

回答

0

誰說你的web服務不能用PHP編寫? Web服務和讀取JSON數據的普通PHP頁面之間沒有太大區別。就像谷歌的「php json網絡服務」,你會得到很多信息。

0

如果您有肥皂服務,您可以通過ksoap訪問肥皂服務。

這裏是例子:

import org.ksoap2.SoapEnvelope; 
import org.ksoap2.serialization.SoapObject; 
import org.ksoap2.serialization.SoapPrimitive; 
import org.ksoap2.serialization.SoapSerializationEnvelope; 
import org.ksoap2.transport.HttpTransportSE; 

public class ChartService { 
private static final String GET_USER_ACTION = "http://service.chartengine.core/getUsersFullNameBasedOnSession"; 
private static final String GET_USER_METHOD_NAME = "getUsersFullNameBasedOnSession"; 
private static final String NAMESPACE = "http://service.chartengine.core"; 
private static final String URL = "http://10.10.10.22:8080/axis2/services/ChartService?wsdl"; 

private static String name = ""; 

public static String getUserFullName(){ 
    if(ECSSecurityService.sessionID.isEmpty()) 
     return ""; 
    SoapObject request = new SoapObject(NAMESPACE, GET_USER_METHOD_NAME); 
    request.addProperty("sessionIDArg", SecurityService.sessionID); 
    final SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
    envelope.setOutputSoapObject(request); 
    final HttpTransportSE ht = new HttpTransportSE(URL); 
    new Thread(new Runnable() { 
     @Override 
     public void run() { 
      try { 
       ht.call(GET_USER_ACTION, envelope); 
       SoapPrimitive response = (SoapPrimitive)envelope.getResponse(); 
       name = response.toString(); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    }).start(); 

    int countWait = 5; 
    while (name.isEmpty() && countWait > 0){ 
     try { 
      Thread.sleep(1000); 
     } catch (InterruptedException e) { 
      e.printStackTrace(); 
      break; 
     } 
     countWait--; 
    } 
    return name; 
} 

} 

此調用5秒超時。希望能幫助到你。

相關問題