【问题标题】:Do I need a webservice or a web api我需要网络服务还是网络 API
【发布时间】:2014-12-01 08:16:06
【问题描述】:

我正在开发一个有点像表单的 android 应用程序。目前它的工作原理是用户输入的数据被解析为 json 到 php 脚本并存储在数据库中。我听说那不是最好的方法,我需要使用 Web 服务/Web API 来与服务器交互,因为这样更安全。我的问题是,我真的需要使用网络服务/API 来发送数据吗?如果我这样做了,你能指导我到一个可以学习如何创建它的资源吗?

【问题讨论】:

    标签: android web-services asp.net-web-api


    【解决方案1】:

    谁说你的 Web 服务不能用 PHP 编写? Web 服务和读取 JSON 数据的普通 PHP 页面之间没有太大区别。只需谷歌搜索“php json web service”之类的内容,您就会获得大量信息。

    【讨论】:

      【解决方案2】:

      如果您有肥皂服务,您可以通过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 秒超时。希望对您有所帮助。

      【讨论】:

        猜你喜欢
        • 2014-03-04
        • 1970-01-01
        • 2011-09-15
        • 2012-03-08
        • 1970-01-01
        • 1970-01-01
        • 2016-11-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多