How to prevent duplicate request in soap object? - android

I have faced a very weird problem by using Soap object in android. I am running a background thread which will take care of sending data to server periodically. Here i am using Soap web service for sending data. While sending a data to server,Sometime duplicate request(double time sending same data) occurs in server.
How to overcome this issue? Please help me...
Thanks in advance...

Firstly check if there's any loop/condition which is causing the error.
Secondly always within a thread whenever HTTP requests are involved make them synchronized and set a boolean whenever request is fired. Reset the boolean ones the response is received successfully and then fire the next request.
These requests for synchronization can be queued in a list and ones a successful response is received remove the request from list else pop the request out and place according to your need (logically back at the end - so that other requests also get a chance if one is failing repetedly).

Related

Is there a way to stop receiving data after service request via volley?

My intention is to stop receiving data from the server after the user has moved away from the activity which has made the service request. The motivation is to reduce the unnecessary bandwidth consumption as the user has navigated away from the activity and hence, the data is no longer required.
As far as I know, in Volley, it is only possible to cancel a request if it's in the request queue and not if it has already been sent.
So, is there any way to refuse the data being sent to the phone from the server or else, change the priority of the data acceptance to a lower level?
You can cancel the Volley Request which means you will not receive the response. When you are initiating Volley Request the request tag and cancel it via tag.
Hope this helps.

Android Service and Http request

I wrote an application with behavior like this: "Android client will run a service to send a request HTTP POST to server, server will return data in JSON and delete it from Database".
Problem I got here is: When i start LoadDataActivity (this activity will start service "GetMessage" to receive data froLm server). If i start LoadDataActivity and finish this activity immediately (Service GetMessage will stop too) , that's mean I sent the HTTP POST to server but I have not receive the JSON result yet, while server deleted it in db, so i lost this data.
Is there anyway to help me fix it, but dont have to keep service still running when finish activity?
What you're doing is a bad idea and you need to change some architecture here.
Just because you sent an HTTP request to a server does not mean that the client will get the response. YOu could lose internet connection. A router can break. Someone can trip over a wire and pull it out. The server could crash after deleting the data but before sending it. It's a bad idea.
If you want to do this, you ought to do 1 of 2 things:
1)Have the client send a 2nd request to the server telling it its ok to delete the data now. Do not do it in one request.
2)Use Lazy Deletion. Rather than actually delete the data, add a column "IsDeleted" to the db. Its default should be 0. After sending the data, set it to 1 rather than deleting it. Then change all queries to the table to only return rows where IsDeleted is 0.
Or 3) 1 and 2 combined. This is the best answer.
As for your direct question- no, there's no way to force the HTTP result to come before an activity is finished. So this needs to be done in a service that is started, not bound. An IntentService would work well, so you could have it automatically terminate itself when the request is done, and it would just start a new instance if another request is pending.

Android:Autobahn - Cancel requests/sendmessage on websocket

Scenario :
1. I have a list view, fetching data on the fly. Due to scrolling what data it might get could be stale.
2. When I implemented HTTP client using a thread , on scroll i would cancel all requests threadHandler.removeMessages(intwhat) so that no stale data was returned.
3. The autobahn Websocket API gives me option to sendmessage and receive its response asynchronously.
4. Can anyone advice me on how to go about cancelling the requests from the WebsocketWriter ? or a work around.
5. If the above description is not sufficient , I can elaborate more.
The OPs question has been taken to the Autobahn mailing list here.
Extract:
sendMessage() cannot be canceled. Upon invoking, it'll forward the
message to the background writer thread, and that thread will send out
the bytes on wire.
What you can do (at app level) is ignore any responses to the sent
message the application expects.

Handle multiple asynchronous responses

I am a web developer and writing services for android. The android developer, whom with I am working, is sending multiple async calls to the server, and asking me to send a service code with in the response of each service, as he will able to decide about a particular response belongs to which service that he sent before.
Is'nt there a way in android to keep track the responses of multiple async calls? Why should the server tell to android that which service is served.
There is no need for the server to send any code . He could send each http request using IntentService with a key. On each response from your server, he puts the key in a bundle, compare it and do what he wants.
See this code : https://github.com/JCERTIFLab/jcertif-android-2013/blob/master/src/com/jcertif/android/fragments/InitialisationFragment.java
I think their is no need of service code to keep track of the response-request pair, because if 5 threads sends the 5 different request, then, all of them receive their responses only.
Order of retrieval of response may vary.
Lets assume a condition,
ThreadA sends requestA.
ThreadB sends requestB.
Then,
ThreadA receives responseA only.
ThreadB receives responseB only.
Order variation:
ThreadB response may come before ThreadA.

How to execute the BluetoothGatt read and write requests one by one like Queue in android?

I'm working in BLE android project.After the successful connection status.I can able to discover the gatt services. But the problem is when doing the write/read request simultaneously. The first request is executed successfully and able to get the response in callback method also. Other requests are ignored by OS.Is there any way to execute one by one like Queue.Kindly suggest best way to implement it.
Thanks.
Execute one request first, then execute the 2nd request inside the 1st request's reponse callback.

Categories

Resources