bulldog2011 / nano

A light Android web serivce client framework
Apache License 2.0
33 stars 30 forks source link

Possible to operate synchronously ? #6

Closed nobre84 closed 11 years ago

nobre84 commented 11 years ago

Hi , is there any option or not so difficult way to implement blocking on the webservice result ? The usage scenario would be for web-services that are already asynchronous by design - i.e they return a Ticket that you poll periodically to verify the task is complete, and retrieve the result later. I'm having kind of a hard time handling state in countless callbacks.

bulldog2011 commented 11 years ago

Hi,

Pico is built on AFNetworking library which seems only supports asynchronous call, I am not sure if there is any simple way to do synchronous call on AFNetworking.

The raw NSURLConnection supports synchronous call, if possible, you may write your own synchronous web serivce library above NSURLConnection, you can leverage the serialization and deserialization part of Pico, the code logic is not complicated, hope you can make it.

Depends on how many user want such feature, I may add sync call in Pico in the future.

Thx! -William

nobre84 commented 11 years ago

I have added a synchronous API to Nano (didn't do it for Pico yet). Currently it may be used such as this, without requiring mwsc changes: SOAPClient client = new SOAPClient(); client.setEndpointURL(...); client.setSynchronous(true); client.callSoapMethod(param, null); //do not supply a callback Serializable result = client.getSynchronousResult(); //this will return the marshalled object received

It is imperative that this API is only used outside of the main application (UI) thread, or the app can become unresponsive (ANR), and ICS+ will raise NetworkOnMainThreadException. Recommended usage: inside Android Service or AsyncTask

bulldog2011 commented 11 years ago

Thx for your work and feedback, can you submit a pull request, so I can integrate.

-William