0

实际上我正在开发一个android应用程序...我需要从.net webservice中获取超过100行..(使用kso​​ap2)..但是当我调用webservice时我得到套接字超时..异常..而不是获取100行我尝试获取 30 行..效果很好..所以我无法识别问题是与 .net webservice 还是在我的 android 中。我只想知道是否有任何替代方法可以同时获取大量数据。

我还添加了权限:

<uses-permission android:name="android.permission.INTERNET" >
</uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

代码:

 package school.demo;
 import java.util.ArrayList;
 import java.util.HashMap;
 import org.ksoap2.SoapEnvelope;
 import org.ksoap2.serialization.SoapObject;
 import org.ksoap2.serialization.SoapSerializationEnvelope;
 import org.ksoap2.transport.HttpTransportSE;
 import android.os.Bundle;
 import android.app.Activity;
 import android.view.View;
 import android.widget.AdapterView;
 import android.widget.AdapterView.OnItemClickListener;
 import android.widget.ArrayAdapter;
 import android.widget.Button;
 import android.widget.GridView;
 import android.widget.TextView;
 import android.widget.Toast;

 public class Code extends Activity {

Button b1;
TextView t1;
String s = "11-10-2012";
int c = 0, j = 0;
ArrayList<String> al = new ArrayList<String>();
HashMap<String, String> map;
private static final String NAMESPACE = "http://TestClass/";
private static final String URL = "http://***.**.**.**/TestClass/Service1.asmx";
private static final String HelloWorld_SOAP_ACTION1 = "http://TestClass/getdata";
private static final String METHOD_NAME2 = "getdata";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.accounts);
    GridView g1 = (GridView) findViewById(R.id.gridView1);
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME2);
    request.addProperty("Uname", s);
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
            SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);

    HttpTransportSE httpTransport = new HttpTransportSE(URL);
    httpTransport.setTimeout(MODE_WORLD_READABLE);
    try {
        httpTransport.call(HelloWorld_SOAP_ACTION1, envelope);

        SoapObject res = (SoapObject) envelope.getResponse();
        SoapObject root = (SoapObject) res.getProperty(0);
        SoapObject s_deals = (SoapObject) root.getProperty("Table1");
        String s = s_deals.toString();
        httpTransport.requestDump="TRUE";
        // Toast.makeText(getApplicationContext(), s,
        //Toast.LENGTH_LONG).show();

        for (int i = 1; i < root.getPropertyCount(); i++) {
            Object o = root.getProperty(i);
            SoapObject main = (SoapObject) o;
            String f1 = main.getProperty(1).toString();
            String f2 = main.getProperty(2).toString();
            String f3 = main.getProperty(3).toString();
            String f4 = main.getProperty(4).toString();
            String f5 = main.getProperty(5).toString();
            //String f6 = main.getProperty(6).toString();
            al.add(f1);
            al.add(f2);
            al.add(f3);

        }
        @SuppressWarnings("unchecked")
        ArrayAdapter a1 = new ArrayAdapter(Code.this, R.layout.blows,
                R.id.textView1, al);
        g1.setAdapter(a1);
        g1.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1,
                    int arg2, long arg3) {
                // TODO Auto-generated method stub
                Toast.makeText(getApplicationContext(), " " + arg2,
                        Toast.LENGTH_LONG).show();
            }
        });
    } catch (Exception e) {
        Toast.makeText(getApplicationContext(), e.toString(),
                Toast.LENGTH_LONG).show();
    }
        }
     }
4

0 回答 0