我正在使用android v4.0.3在我的应用程序中使用web服务,但是当我到达时
HttpTransportse
显示SocketTimeoutException
但未获得响应。相同的代码在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
}
});
}
}
答案 0 :(得分:0)
我花了近2-3个小时来解决这个问题,解决方案非常简单。当您在错误的IP上访问Web服务或服务有一些问题时,会出现此问题。但除了这两个之外,还有一点需要注意,即如果Web服务在Http上托管,那么您应该使用HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
,如果您的Web服务是https,那么请使用HttpsTransportSE aht = new KeepAliveHttpsTransportSE(IP, 443,SERVICEPATH, 25000);
。我希望能帮助你。