【问题标题】:Dataset web service from android eclipse来自 android eclipse 的数据集 Web 服务
【发布时间】:2012-06-14 07:07:40
【问题描述】:

谁能告诉我如何通过在 android eclipse 中使用来显示来自 web 服务的数据集值?

到目前为止我已经尝试过这些东西

public class Demo_webserviceActivity extends Activity
{
/** Called when the activity is first created. */

   private static String NAMESPACE = "http://tempuri.org/";
   private static String METHOD_NAME = "GetName";
   private static String SOAP_ACTION = "http://tempuri.org/GetName";
   private static String URL = "http://122.248.240.105:234/Service1.asmx?WSDL";

   Button btnFar;
   EditText txtFar,txtCel;

   @Override
   public void onCreate(Bundle savedInstanceState)
   {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);

       btnFar = (Button)findViewById(R.id.btnFar);

       txtFar = (EditText)findViewById(R.id.txtFar);
       txtCel = (EditText)findViewById(R.id.txtCel);

       btnFar.setOnClickListener(new View.OnClickListener()
       {

                  public void onClick(View v)
              {
                    //Initialize soap request + add parameters
              SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);       

              //Use this to add parameters
              request.addProperty("Fahrenheit",txtFar.getText().toString());

              //Declare the version of the SOAP request
              SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

              envelope.setOutputSoapObject(request);
              envelope.dotNet = true;

              try {
                    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

                    //this is the actual part that will call the webservice
                    androidHttpTransport.call(SOAP_ACTION, envelope);

                    // Get the SoapResult from the envelope body.
                    SoapObject result = (SoapObject)envelope.bodyIn;

                    if(result != null)
                    {
                          //Get the first property and change the label text
                          txtCel.setText(result.getProperty(0).toString());
                    }
                    else
                    {
                          Toast.makeText(getApplicationContext(), "No Response",Toast.LENGTH_LONG).show();
                    }
              } catch (Exception e) {
                    e.printStackTrace();
              }
              }
        });

网络方法

public class GetName 
{

public String GetName(String Fahrenheit){
    return(Fahrenheit);
}
}

这是我的日志猫供参考

logcat

06-11 17:03:57.760: D/AndroidRuntime(283): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
06-11 17:03:57.760: D/AndroidRuntime(283): CheckJNI is ON
06-11 17:03:57.890: D/AndroidRuntime(283): --- registering native functions ---
06-11 17:03:58.520: D/AndroidRuntime(283): Shutting down VM
06-11 17:03:58.530: D/dalvikvm(283): Debugger has detached; object registry had 1  entries
06-11 17:03:58.580: I/AndroidRuntime(283): NOTE: attach of thread 'Binder Thread #3' failed
06-11 17:03:58.980: D/AndroidRuntime(291): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
06-11 17:03:58.980: D/AndroidRuntime(291): CheckJNI is ON
06-11 17:03:59.150: D/AndroidRuntime(291): --- registering native functions ---
06-11 17:03:59.750: I/ActivityManager(58): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.demo.webser/.Demo_webserviceActivity }
06-11 17:03:59.820: D/AndroidRuntime(291): Shutting down VM
06-11 17:03:59.820: D/dalvikvm(291): Debugger has detached; object registry had 1 entries
06-11 17:03:59.865: I/AndroidRuntime(291): NOTE: attach of thread 'Binder Thread #3' failed
06-11 17:04:00.560: I/ActivityManager(58): Displayed activity com.demo.webser/.Demo_webserviceActivity: 780 ms (total 780 ms)
06-11 17:04:05.930: D/dalvikvm(115): GC_EXPLICIT freed 2114 objects / 95232 bytes in 117ms

【问题讨论】:

  • 这是什么意思?到目前为止,您尝试过什么?
  • Sebastin 请再次访问我的问题,我已经编辑了我到目前为止所做的事情
  • 您正在使用哪个平台开发网络服务,以便我可以帮助依赖它

标签: android eclipse web-services dataset


【解决方案1】:

我认为您正在使用 Java 开发 Web 服务。 不,没有数据类型作为 java 中的数据集,但如果您愿意,您可以将响应作为字符串数组返回。这意味着在字符串的二维数组中获取响应(表)并返回该响应。

使用本教程How to create java based web service 供您参考在 java 中创建 web 服务。

如果您对此有任何疑问或任何其他疑问,可以给我写信。

【讨论】:

    猜你喜欢
    • 2013-07-06
    • 2017-07-07
    • 1970-01-01
    • 2015-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多