我開發了使用ksoap庫並與.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();
}
我使用的是ksoap 2.6.5版本,連接在所有API上都是一樣的。嘗試下載最後的ksoap版本。 – kinghomer
我做到了。即時通訊使用現在版本3.0.0 RC.4。仍然一樣... –
嘗試將您的項目屬性設置爲4.0。順便說一下,我認爲問題不是ksoap。然後,發佈您的肥皂調用方法 – kinghomer