2012-11-22 30 views
0

我開發了使用kso​​ap庫並與.NET Web服務進行通信的軟件。從android 2.2到2.3.3的ksoap2通信切換應用程序

所有在Android 2.2版本中都能正常工作。

最近,我被迫遷移到2.3.3 Android版本。

我剛剛在項目屬性更改爲2.3.3並編譯。

有一些錯誤,但誰令我擔心最多的是與Web服務的通信 是真的很慢的一個...

我使用KSOAP 2.5.7版本...

和想法?

在此先感謝!

我也求函數:

public void MakeRequest(final String MethodName, 
     final PropertyInfo[] props, final ResponseListener resListener, 
     final int timeout, final int retries) 
{ 

    GeneralMethods.debug(this.getClass().toString(), "MakeRequest", 
      "MethodName=" + MethodName); 
    for (PropertyInfo prop : props) 
    { 
     if (prop != null && prop.getValue() != null) 
      GeneralMethods.debug(this.getClass().toString(), "MakeRequest", 
        prop.name + "=" + prop.getValue().toString()); 
    } 

    final Handler uiThreadCallback = new Handler(); 

    final Thread RequestThread = new Thread() 
    { 
     public void run() 
     { 
      try 
      { 

       SoapObject Request = new SoapObject(NAMESPACE, MethodName); 

       // adding properties 
       if (props != null) 
        for (PropertyInfo pi : props) 
        { 
         if (pi.getValue() != null 
           && isComplexType(pi.getValue().getClass() 
             .getName())) 
         { 
          PropertyInfo complexProp = new PropertyInfo(); 
          complexProp 
            .setValue(getSoapClass(pi.getValue())); 
          complexProp.setName(pi.getName()); 
          Request.addProperty(complexProp); 

         } 
         else 
          Request.addProperty(pi); 
        } 

       // Set the web service envelope 
       SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
         SoapEnvelope.VER11); 
       envelope.dotNet = true; 
       envelope.setOutputSoapObject(Request); 
       HttpTransportSE androidHttpTransport = new HttpTransportSE(
         URL, timeout); 
       androidHttpTransport.debug = true; // TODO: comment it on 
                // finish debug 

       // Load cookies 
       List<HeaderProperty> httpHeaders = new ArrayList<HeaderProperty>(); 
       for (String cookie : cookies.keySet()) 
       { 
        httpHeaders.add(new HeaderProperty("Cookie", cookie 
          + "=" + cookies.get(cookie))); 
       } 

       // Call the web service and retrieve result 


       @SuppressWarnings("rawtypes") 
       List reshttpHeaders = androidHttpTransport.call(NAMESPACE 
         + MethodName, envelope, httpHeaders); 


       // save cookies 
       Log.d("DEBUG OUTGOING XML", 
       androidHttpTransport.requestDump); 
       androidHttpTransport.debug = true; 
       Log.d("DEBUG INCOMING XML=========================================", 
       androidHttpTransport.responseDump); 
       if (reshttpHeaders != null) 
       { 
        for (int i = 0; i < reshttpHeaders.size(); i++) 
        { 
         HeaderProperty hp = (HeaderProperty) reshttpHeaders 
           .get(i); 
         String key = hp.getKey(); 
         String value = hp.getValue(); 
         if (key != null && value != null) 
         { 
          if (key.equalsIgnoreCase("set-cookie")) 
          { 
           String cookieString = value.substring(0, 
             value.indexOf(";")); 

           cookies.put(cookieString.substring(0, 
             cookieString.indexOf("=")), 
             cookieString.substring(cookieString 
               .indexOf("=") + 1)); 
           break; 
          } 
         } 
        } 

       } 
       // Log.i("test", httpHeaders.toString()); 
       // final Object res = envelope.getResponse(); 
       final Object res = envelope.getResponse(); 
       uiThreadCallback.post(new Runnable() 
       { 
        public void run() 
        { 
         // Log.i("Talk2Doc", res.toString()); 
         GeneralMethods.debug(this.getClass().toString(), 
           "MakeRequest", "Responce -> MethodName=" 
             + MethodName); 

         resListener.onGotResponse(res); 

        } 
       }); 

      } 
      catch (final Exception e) 
      { 
       GeneralMethods.debug(this.getClass().toString(), 
         "MakeRequest", "Error -> MethodName=" + MethodName 
           + ", Error=" + e.getMessage()); 
       uiThreadCallback.post(new Runnable() 
       { 
        public void run() 
        { 

         e.printStackTrace(); 

         if (e.getMessage().contains("login failed")) 
          resListener.onLoginError(); 
         else 
         { 

          if (retries < 1 
            || e.getClass() == SocketTimeoutException.class) 
           resListener.onResponseError(e); 
          else 
          { 
           // retry 

           MakeRequest(MethodName, props, resListener, 
             timeout, retries - 1); 

          } 

         } 

        } 
       }); 

      } 
     } 
    }; 
    RequestThread.start(); 

} 
+0

我使用的是ksoap 2.6.5版本,連接在所有API上都是一樣的。嘗試下載最後的ksoap版本。 – kinghomer

+0

我做到了。即時通訊使用現在版本3.0.0 RC.4。仍然一樣... –

+0

嘗試將您的項目屬性設置爲4.0。順便說一下,我認爲問題不是ksoap。然後,發佈您的肥皂調用方法 – kinghomer

回答

0

在您的項目清單文件試試這個剛剛成立的最低SDK版本爲8。並回復結果。 即android:minSdkVersion="8"AndroidManifest文件並回復我的結果。

+0

hey sachin D,它一直都是這樣的...(<使用sdk的android:minSdkVersion =「8」/>) –

+0

我試圖連接相同的web服務與httpclient沒有ksoap和所有的作品都很好。 ..但這個應用程序有非常大的溝通層...我寧願不這樣做... –

+0

我添加了代碼。你現在可以看到它。 –

相關問題