views:

68

answers:

3

I am using C# to write a program that uses a web service from http://msrmaps.com, the problem is sometimes (seemingly at random) the site won't work properly and will return a few different exceptions. Then on subsequent attempts to use the service I get the error over and over, then after a while (sometimes 30 minutes) the service starts working properly again. In order to avoid waiting for the service to work properly again, I usually just close my program and start it back up again. Usually that fixes the problem and I can continue to use the web service.

My question: Is it possible to restart my program within the program or better yet is there a way to somehow re-connect to the web service like the program does when I first run it?

+3  A: 

What is the program actually doing that depends on the web service? Does it really need to be re-started? It sounds like you should be able to just have some UI element in the application that attempts to connect to the service. Wrap that connection in some exception handling and somewhere in the application's UI display that the service connection is currently unavailable.

Or am I way off here?

David
+1 a call to an external system should be appropriately wrapped with error handling when said system/service availability is beyond control
RandomNoob
The program is attempting to download a tile image using the web service described at "http://msrmaps.com/TerraService2.asmx". The program itself really doesn't need to be re-started, but somewhere during the restarting of the program the web service is connected to and works when previously it was getting the exception. I was hoping there was some way to connect back to the web service without having to restart the program. I believe the service is still avialable, except that the site has been behaving strangely lately. After refreshing it a few times it will come back up again.
Mawk
@Mawk: It shouldn't have to be re-started, web service connections aren't persisted. The application should be able to hit the same web service over and over until it has what it needs. If the service is only hit once when the application starts then it sounds like that bit of logic needs to move into a common function that's called when the application starts, or when manually initiated, or when some other condition is met (such as an interval of time in which the service hasn't been re-hit since a previous exception), etc.
David
@David: When you say the application should hit the same web service over and over do you mean like when I call a method on the web service such as http://msrmaps.com/TerraService2.asmx?op=GetAreaFromRect ? My application calls this method repeatedly, but for stretches of time it will just return a "System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: http://msrmaps.com/GetAreaFromRect." exception for 20-30 minutes and then continue working properly again. If I restart the application when I see the exception, that exception doesn't occur.
Mawk
@Mawk: So it already calls the service repeatedly, it just gets locked in a cycle of exceptions from which it can't break free without a restart? Or do the exceptions eventually end without a restart? I guess what matters now is the pattern of errors. If it happens regardless of restart frequency for a given window, then the service is just down. If it happens endlessly until the application is restarted then there may be something wrong with the application, possibly unrelated to the calling of the service.
David
@David Yes, it calls the service repeatedly. Although it eventually will break free of the exceptions without a restart(up to 30 minutes), the exceptions usually do not persist after restarting the application. It's some strange middle ground. I don't fully understand how the web services work, but to me it seems like each call I make goes to an available computer on the server, some aren't updated to the new namespace and so I get the exceptions. Others aren't working at all so I get some out of service errors. The rest of them work just fine and things run smoothly.
Mawk
A: 

Warning: This is a bit of a hack, but it works.

I'm assuming your application is unattended, so a UI change alerting the user to the need to shut down and restart is not an option.

We had a similar situation where the simplest resolution to a problem was to shut down and restart my app. (We'll call this "App A").

What I wound up doing was writing a second executable (We'll call it "App B") as a console app that did two things.

  1. It used the System.Diagnostics.Process to kill any instance App A.
  2. Use System.Diagnostics.Process to re-launch App A after all instances were killed.

Then in App A, I had a try/catch around the offending code, and when the error I was looking for came up, it would call App B.

This was the only way I could find of killing a program and relaunching it. If anyone has a better solution, PLEASE post it and I'll change my hack to use a better solution.

David Stratton
I could prompt the user to restart the program, but I would like to avoid that and somehow reconnect to the the web service behind the scenes.
Mawk
I may have to try something like this, although I am also hoping there is a better solution. Thanks.
Mawk
A: 

I would check that you don't have too many simultaneous requests happening at the same time due to each waiting for a long time before returning (and relatedly, that the total allowed connections as per machine.config is high enough). Throttling code can be very useful with unattended use of web-services (or any other remote service), if you've had a few failures in a row then wait a while before allowing another request to be made (I like to roll forward the wait period each time, starting a around a minute, maxing the wait at around 10minutes).

Then while you can't guarantee the other service won't go down, you can help prevent it causing a permanent problem, or reducing the performance of other processes.

Jon Hanna
When the problem occurs I usually only have one request happening, although there may be many more coming from other people accessing the web service. I have actually tried using the wait periods and for the most part that does seem to work. Although the application can be left unattended, I would like to come up with a faster way to get things back up and running. So I am hoping someone has an idea of why restarting the application and trying again fixes the problem and if I can make that happen within my program.
Mawk