Async Service Call with Timeout Exception problem

Topics: CAB & Smart Client Software Factory
Mar 18, 2006 at 8:13 AM
originally posted by: mqlin

Hi,

I am designing a BAT smart client application with backend SOA web service 1.1. I design my web service to through soap exception when user has invalid user name and password. I would like to catch this exception to get the error message and display to user.

I found that the BAT web service call that suppress all the exceptions adn redirect to Event Log, it only returns a single variable "success". I wonder is there way I can return error code or error message from web service using BAT?

Thank you in advance.
Sep 19, 2006 at 12:29 PM
originally posted by: puy0

Same problem here, i wish this thread had answers...

Appraisal > no custom exceptions throwed from services. (such a perfect world doesnt exists!)
BankBranch > SoapExceptions throwed, but no usage of ServiceProxy / CommandQueue to handle Async with Timeouts...
And with .NET2, Exeptions + Threads = http://msdn2.microsoft.com/en-us/library/ms228965.aspx

Will dig deeper in this forums...

I think there is a "big hole" in this factory with exception handling or maybe i'm missing something...
...Please tell me i'm missing something, and tell me what it is!

Thanks,
Vincent.
Sep 19, 2006 at 10:43 PM
originally posted by: akol_dk

We had the same problem in our project, so we decided to modify the code. I include our code here, so you can see the changes we have made.

We are using an AsyncCompletedEventArgs object to return results as you can see below. I think it works quite well.

Infrastructure.Interface.Commands.CommandWithCallback:
-------------------------------------------------------------------
using System;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;

namespace Energinet.DPSApp.Client.Infrastructure.Interface.Commands
{
public abstract class CommandWithCallback<TService, TReturnType> : Command<TService>
where TService : ISupportsTimeout
{
public delegate void CallbackType(CommandCompletedEventArgs<TReturnType> args);

private CallbackType _callback;

protected CommandWithCallback(TService service, int timeout, CallbackType callback)
: base(service, timeout)
{
_callback = callback;
}

protected override sealed void DoExecute()
{
TReturnType returnValue = default(TReturnType);
Exception error = null;

try
{
returnValue = DoCallService();
}
catch (Exception ex)
{
ExceptionPolicy.HandleException(ex, "Default Policy");
returnValue = default(TReturnType);
error = ex;
}

CommandCompletedEventArgs<TReturnType> res = new CommandCompletedEventArgs<TReturnType>(returnValue,error,false,null);
_callback(res);
}

protected abstract TReturnType DoCallService();
}
}


Infrastructure.Interface.Commands.CommandCompletedEventArgs:
---------------------------------------------------------------------------

namespace Energinet.DPSApp.Client.Infrastructure.Interface.Commands
{
public class CommandCompletedEventArgs<TResultType> : System.ComponentModel.AsyncCompletedEventArgs
{
private TResultType result;

public CommandCompletedEventArgs(TResultType result, System.Exception exception, bool cancelled, object userState)
: base(exception, cancelled, userState)
{
this.result = result;
}

public TResultType Result
{
get
{
this.RaiseExceptionIfNecessary();
return result;
}
}
}
}


If you can use any of our code, go ahead and do so.

Regards
Anders