Advice on Handling Lost Server Connections


This is a repost of a question from a few weeks ago which was inadvertently deleted due to changes on the board.

I was wondering if Extensis has any recommendations or sample code on how to handle situations were an AssetSEIService has logged-in to a Portfolio Server, but then experiences an interruption in its network connection.

For example, what should be done to allow the following call…

…to throw an error or fail gracefully if the AssetSEIService has lost the network connection the Portfolio Server it’s communicating with?

I’m primarily working in C#. Thanks!


Hi Alex,

You can wrap your code in a Try:Catch block. This will Try to run the command, and will Catch any Exceptions that you specify. What do with those Exceptions is up to you.

Here is an example:

    _assetId = _PortfolioServer.addAssetsByPath(_sessionId, _catalogId, _theAssetPath);
catch (Exception err)
    if (err is SoapException ||
        err is System.Net.WebException)
        Console.WriteLine("An error occurred: {0}", err.Message);

In this code sample, I am catching any Exceptions that occur and checking for SoapExceptions and WebExceptions. SoapExceptions will be thrown by the command if there is a problem with the Portfolio command, such as a bad CatalogID. A WebException will be thrown if there is a communication problem with the Portfolio server, such as a lost connection. In both these cases, the error will be caught, a message will be printed to the command line, and then the application will exit.

If you have any questions about this example, please let me know.