我开发了使用ksoap库并与.NET Web服务通信的软件。
在Android 2.2版本中,所有工作都很好。
最近,我被迫转向2.3.3 Android版本。
我刚刚将项目属性更改为2.3.3并进行编译。
有一些错误,但最让我担心的是沟通 网络服务真的很慢......
我正在使用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 :(得分:0)
尝试将项目清单文件中的最小sdk版本设置为8。并回复我的结果。
即android:minSdkVersion="8"
文件中的AndroidManifest
并回复结果。