KSoap2-Android have long be the library to use for soap request. But for our android development we also needed timeout when using soap requests.
Currently Ksoap2 only support timeout for https, but we have modified version 2.5.2 to also support timout for http, that we needed. You will find the download below.
Official KSoap2 project-page is found here
And Official Ksoap2-Android here
[sourcecode language=”java”]
/**
* Creates instance of HttpTransportSE with set url
*
* @param url
* the destination to POST SOAP data
*/
public HttpTransportSE(String url) {
super(url);
}
/**
* Creates instance of HttpTransportSE with set url
*
* @param url
* the destination to POST SOAP data
* @param timeout
* timeout for connection and Read Timeouts (milliseconds)
*/
public HttpTransportSE(String url, int timeout) {
super(url, timeout);
}
[/sourcecode]
[ad#LightSoft – Banner – Image]
Download the entire jar file:
[download id=”1″]
Or source: [download id=”2″]
15 thoughts on “ksoap2 with timeout for HttpTransportSE”
Thanks!!
Andreas,
I still have cases where the call never times out. For example, if I use:
HttpTransportSE aht = HttpTransportSE(url, 10000);
try {
aht.call(soapAction, soapEnvelope);
etc…
very occasionally it gets hung. Since it is so random, it is very difficult to troubleshoot, so I don’t have any more info at this time.
Should I also try aht.setTimeout(10000); before issuing the call?
Kim
@Kim Knapp
Ok, I should take a look at it again and debug it.
But as this is only passed it to HttpURLConnection, that should handle the timeout.
It is possible to add a timer when reading the inputstream as well, but I expect that HttpURLConnection should handle this since it is part of JDK.
A little more info:
Background:
I am polling our CasaTunes web services every couple of seconds on WiFi when in the Now Playing activity, which works fine. When the user goes to the Select Music activity, the polling is stopped and then the Select Music activity sends a web call that reads a couple of packets of data or more. This also works fine and is pretty quick.
When it goes wrong:
When the phone goes to sleep, the Now Playing activity finishes its current poll and then stops polling.
When it wakes up, it starts polling. If during the poll, the web services don’t respond, the activity waits for about 9 seconds to start another poll. Often, it takes a number of these cycles before the activity finally gets a response and the polling starts acting normal. If, while waiting for the polling to start working, the user goes to the Select Music activity, the web service call that goes out to request music information hangs forever.
So, I suspect that in the Now Playing activity the fact that I am starting new web service calls every 9 seconds finally gets things going, but when in the Select Music routine, where I just send one call, it never times out and there is no second call to “get things going” again. The only recourse when this happens is for the user to Force Stop the app in the Android Settings|Applications screen. Also, turning off the WiFi causes a Force Stop from our app, which can be used to shut it down. Not very elegant! 🙂
I am thinking of putting my own timeout in the Select Music call and retry every so often to see if it eventually comes back when in this condition.
I mentioned before that it is very random, but since I changed the Now Playing activity to shut down polling when going to sleep, I am actually seeing it more often. I’ll try to grab more info and maybe look at WireShark results.
Will you send your code to ksoap2-android developers?
I’ve encountered the same situation, and will be glad if this will be merged with original codebase.
@Kim Knapp
Have you still the problem? I haven’t been able to test it yet.. Maybe have some time this weekend.
@kotov
Yes, this code if they accept it will be merged into the codebase.
I am getting the below warning on my Eclipse console when i use HttpTransportSE for setting timeout. I am using ksoap2-android-assembly-2.5.4-jar-with-dependencies
Ignoring InnerClasses attribute for an anonymous inner class (org.ksoap2.transport.KeepAliveHttpsTransportSE$1) that doesn’t come with an associated EnclosingMethod attribute. This class was probably produced by a compiler that did not target the modern .class file format. The recommended solution is to recompile the class from source, using an up-to-date compiler and without specifying any “-target” type options. The consequence of ignoring this warning is that reflective operations on this class will incorrectly indicate that it is not an inner class.
pl guide
Ash – same problem here. Timeout is not working. Any idea? See:
http://stackoverflow.com/questions/5489671/ksoap-never-timeout
Will take a look at it this week to see if I got the same error. The timeout wasn’t any problem for me since my thread was timing out. But could maybe be something with the compilation.
Hi !
Have you compiled the source code you tried the JAR file here in this post?
Want to sort out how first =)
Had have some problem on getting time to do this, but tonight or tomorrow early I will check into this.
Is the timeout not working when the normal connection works aswell? (For example when the server takes to long time to execute the request and the answer its self is timed out)
About the warnings:
http://stackoverflow.com/questions/3308010/how-to-solve-the-waning-in-android
Could be that it is compiled with another version of java then the one you are running on.
Hi
Android need to consume WCF , that particular method returntype is C# DataTable.
When I process the soap respons ,
(using
// ksoap2 calling wcf
public SoapObject soap(String METHOD_NAME, String SOAP_ACTION, String NAMESPACE, String URL) throws IOException, XmlPullParserException {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); //set up request
request.addProperty(“strExec”, “7067”);
request.addProperty(“strBusinessUnit”, “HEMA”);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); //put all required data into a soap envelope
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
AndroidHttpTransport httpTransport = new AndroidHttpTransport(URL);
httpTransport.debug = true;
try{
Log.w(“log_tag”, ” ===========” +SOAP_ACTION.toString() );
Log.w(“Log_cat” ,”*********” + envelope.toString());
httpTransport.call(SOAP_ACTION, envelope);
}
catch(Exception e)
{
e.printStackTrace();
}
SoapObject responses = (SoapObject)envelope.getResponse();
return responses;
}
public String[] getStringArrayResponse(SoapObject node, Vector strings) {
boolean isFirstCall = false;
if (strings == null) {
isFirstCall = true;
strings = new Vector();
}
int count = response.getPropertyCount();
for (int i = 0; i 0) {
getStringArrayResponse((SoapObject)obj1, strings);
}
} else if (obj1 instanceof SoapPrimitive) {
strings.add(((SoapPrimitive)obj1).toString());
}
}
// only make this for the original caller
if (isFirstCall) {
return (String[])strings.toArray(new String[strings.size()]);
}
return null;
}
),
Its error is:
anyType{element=anyType{complexType=anyType{choice=anyType{element=anyType{complexType=anyType{sequence=anyType{element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; }; }; }; }; }; }; }
Please help me.Its urgent. Please guide me what is wrong?
Thanks in advance
I used to use setTimeout and that was working perfectly on many Android devices until my app was installed on Samsung Charge. Once setTimeout method is called, my app crashes. If I remove setTimeout from the code, the app works fine. However, if internet connection is dropped during the web service call, the application hangs. If I use
HttpTransportSE htransport = new HttpTransportSE(URL, 9000);
the application hangs if the connection is dropped.
1- This problem seems common, has anyone found a solution for it?
2- Has anyone experienced the setTimeout crash on Samsung Charge?
Newbie here. I started out using HttpTransportSE htransport = new HttpTransportSE(URL, 9000). I have never used .setTimeout. Which one is better? How do they differ?
@Ayman I haven’t tried it on a Charge. I will be trying on my EVO.