Xamarin.Android handling connection failures when calling web service

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?

Best Answer

Answers

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
    Sorry but I think this is not a Xamarin problem.
  • BillyLiuBillyLiu Member, Xamarin Team Xamurai

    @thebigbo

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

  • thebigbothebigbo Member ✭✭
    edited August 2018

    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?

Sign In or Register to comment.