1

我在使用 android v4.0.3 的应用程序中使用 web 服务,但是当我到达 HttpTransportseShowsSocketTimeoutException并没有得到响应时。相同的代码在 android.v.2.2 中完美运行

我在 logcat 中得到以下异常

05-10 11:18:38.245: W/System.err(849): java.net.SocketTimeoutException
05-10 11:18:38.255: W/System.err(849):  at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:130)

KSoap jar
---------
KSoap2 library android:2.5.2.jar

这是代码

public class busTravellDetailslistActivity extends Activity {
/** Called when the activity is first created. */
Button b;
EditText rteid,trvname,bustyp,deptm,arvtm;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    b=(Button) findViewById(R.id.button1);
    b.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {


            SoapObject request = new SoapObject("http://***********/WS2","TestRouteDataMobile");
                //System.out.println("req count:"+request.getPropertyCount()); 
            SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);

              envelope.setOutputSoapObject(request);

              HttpTransportSE transport = new HttpTransportSE("http://**********/RouteSearchService.asmx");//namespace
                try {

                    transport.call("http://***********/TestRouteDataMobile",envelope);
                    System.out.println("aftr call");
                } catch (SocketTimeoutException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (XmlPullParserException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                    SoapObject response;
                    try {
                        response = (SoapObject)(envelope.getResponse());

                        Log.i("Response",response.toString());




                    } catch (SoapFault e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

            // TODO Auto-generated method stub

                }
    });
    }
}
4

1 回答 1

0

我花了将近 2-3 个小时来解决这个问题,解决方案非常简单。当您以错误的 IP 访问 Web 服务或服务出现问题时,就会出现此问题。但是除了这两个之外,您需要注意一件事,即如果 Web 服务托管在 Http 上,那么您应该使用HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);,如果您的 Web 服务位于 https,则使用HttpsTransportSE aht = new KeepAliveHttpsTransportSE(IP, 443,SERVICEPATH, 25000);. 我希望能帮助你。

于 2013-03-08T07:52:31.657 回答