0

Hi currently I am trying to check if the Ria Service is available for our OOB application.

 public static void IsServiceReachable(Action onServiceAvailable, Action onServiceUnavailable)
       {
            try {
                DomainContext context = new DomainContext();

                InvokeOperation<bool> invokeOperation = context.IsAlive();
                invokeOperation.Completed += (s, arg) => onServiceAvailable();
            }
            catch (Exception) {
                onServiceUnavailable();
            }
        }

When the exception happen my App hangs, and is now just a white screen. Am I doing it correctly?

I am also using MEF in the app, I am lazy importing my views, sadly when Ria Service is not reachable, MEF doesnt import my views :( I am calling CompositionInitializer.SatisfyImports(this).

[ImportMany(AllowRecomposition = true)]
public Lazy<BaseUserControl, IViewMetadata>[] Views { get; set; }
arcbound08
  • 107
  • 8
  • put a breakpoint in app.xaml.cs on the applicationerror_unhandeld method, you might get a detailed expection on whats going on – Rik van den Berg Mar 21 '12 at 09:21
  • Thanks, sadly I already checked it and nothing is thrown there. For now what I am currently checking is why MEF is not importing my views :( – arcbound08 Mar 21 '12 at 09:30

1 Answers1

0

Have you tried checking if an error has occured in the OnServiceAvailable callback:

void OnServiceAvailable(object sender, EventArgs e)
{
    InvokeOperation op = sender as InvokeOperation;
    if (op.HasError) {
        Exception exception = op.Error;
        ...
    } else {
        ...
    }
}

You should probably rename OnServiceAvailable something like OnOperationComplete.

You have to handle the errors in the callback - including the 'ServiceNotAvailable' error. Remember this is an asyncronous call - the client does does not wait for the server response before it continues.

GarethOwen
  • 6,075
  • 5
  • 39
  • 56
  • I don't think it can work cause the OnServiceAvailable wont be call cause I am checking if ria is reachable or not. – arcbound08 Mar 23 '12 at 07:17
  • The client will still be sending an HTTP request. The 'Completed' callback function will get called, where the exception and error code will be available - probably a 'bad gateway' exception (http code 502). – GarethOwen Mar 23 '12 at 07:51
  • Thanks, tried it, you are correctly about it. Sadly MEF is still not importing my views. At least it is not hanging anymore :) The message i get from the invoke operation is: "Invoke operation 'IsAlive' failed. The remote server returned an error: NotFound." – arcbound08 Mar 23 '12 at 08:17
  • Found the issue when Ria Service is not reachable no XAP files are loaded – arcbound08 Mar 26 '12 at 09:28