2012-05-10 75 views
1

我使用的是Web服務在我的應用程序採用了android V4.0.3,但是當我在 達到HttpTransportse顯示SocketTimeoutException並沒有得到response.The相同的代碼在android.v.2.2了socketTimeout異常當調用

工作完美web服務

我有以下異常在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

請上傳你的代碼 – Lucifer

+0

我上傳了代碼 – Nijosusan

+0

ok了,我有同樣的問題,只是你需要在迴應後清理變量。 – Lucifer

回答

0

我有餘度t幾乎2-3小時才能解決這個問題,解決方案非常簡單。如果您以錯誤的IP訪問Web服務或服務出現問題,則會出現此問題。但除了這兩者之外,還有一件事需要注意,即如果Web服務託管在Http上,那麼您應該使用HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);,如果您的Web服務位於https,則使用HttpsTransportSE aht = new KeepAliveHttpsTransportSE(IP, 443,SERVICEPATH, 25000);。我希望能幫助你。