locked
Xamarin.Android handling connection failures when calling web service RRS feed

  • Question

  • User365813 posted

    We're developing warehouse app for picking items which sends requests to a web service on every item scan, e. g. to update the quantity scanned in DB. From the log files I saw thet every now and then the connection on android scanners is lost and that leads to item quantity not being updated or in worst case an app crash.

    What would be the best way to handle such connection failures so that I can ensure that the call to web method was successul before continuing code execution? Should I define some variable which accepts response from the web method and repeat the call until success is returned? Or is there some smarter way?

    Sunday, August 5, 2018 1:43 PM

Answers

  • User21936 posted

    @thebigbo

    This is kind of a big question.

    Since you have no control over the internet connection of a user, you should always be prepared for times when there is no connection. What I would do is if there is no connection, then you should cache the data locally so that when you have a connection again, you can upload all of the data that was scanned when the network was not connected. So whenever you have cached data, you can silently test the connection every so often and once connected upload all of the cached data.

    And an Android Broadcast Receiver has nothing to do with network connectivity.

    ConnectFailure (Network is unreachable) errors can happen for any number of reasons. If it is so constant as to be unusable, then yes having your client set up better WiFi at their warehouse is likely the only solution. Any system is only as good as its weakest link, so you cold write the best, fastest, network code ever written but it will still perform poorly if you have a poor internet/network connection.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, August 23, 2018 8:39 PM

All replies

  • User2148 posted

    Sorry but I think this is not a Xamarin problem.

    Sunday, August 5, 2018 6:24 PM
  • User364855 posted

    @thebigbo

    Have you used try-catch to handle such connection failures?

    Friday, August 10, 2018 8:58 AM
  • User365813 posted

    I used the Polly library from NuGet to retry webservice calls should they fail with webexception but don't want to retry every single method I call. Still need a better solution, e. g. display alert on screen and wait while internet reconnects.

    Side questions: What could be the reason for frequent ConnectFailure (Network is unreachable) errors? Will the usage of Broadcast Receiver prevent them from happening if I just display alert on screen while retrying the connection? If yes, what's the simplest way of implementing it? Or should I just tell the client to fix their internet connection?

    Friday, August 17, 2018 10:42 AM
  • User21936 posted

    @thebigbo

    This is kind of a big question.

    Since you have no control over the internet connection of a user, you should always be prepared for times when there is no connection. What I would do is if there is no connection, then you should cache the data locally so that when you have a connection again, you can upload all of the data that was scanned when the network was not connected. So whenever you have cached data, you can silently test the connection every so often and once connected upload all of the cached data.

    And an Android Broadcast Receiver has nothing to do with network connectivity.

    ConnectFailure (Network is unreachable) errors can happen for any number of reasons. If it is so constant as to be unusable, then yes having your client set up better WiFi at their warehouse is likely the only solution. Any system is only as good as its weakest link, so you cold write the best, fastest, network code ever written but it will still perform poorly if you have a poor internet/network connection.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, August 23, 2018 8:39 PM