2014-10-07 65 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秒超时。希望能帮助到你。