Rescuing a failed WCF call

Posted by illdev on Stack Overflow See other posts from Stack Overflow or by illdev
Published on 2010-05-17T15:37:40Z Indexed on 2010/05/17 15:40 UTC
Read the original article Hit count: 244

Hello,

I am happily using Castle's WcfFacility. From Monorail I know the handy concept of Rescues - consumer friendly results that often, but not necessarily, contain Data about what went wrong. I am creating a Silverlight application right now, doing quite a few WCF service calls. All these request return an implementation of

public class ServiceResponse
{
    private string _messageToUser = string.Empty;
    private ActionResult _result = ActionResult.Success;

    public ActionResult Result // Success, Failure, Timeout
    {
        get { return _result; }
        set { _result = value; }
    }

    public string MessageToUser
    {
        get { return _messageToUser; }
        set { _messageToUser = value; }
    }
}

public abstract class ServiceResponse<TResponseData> : ServiceResponse
{
    public TResponseData Data { get; set; }
}

If the service has trouble responding the right way, I would want the thrown Exception to be intercepted and converted to the expected implementation. base on the thrown exception, I would want to pass on a nice message.

here is how one of the service methods looks like:

    [Transaction(TransactionMode.Requires)]
    public virtual SaveResponse InsertOrUpdate(WarehouseDto dto)
    {
        var w = dto.Id > 0
                    ? _dao.GetById(dto.Id)
                    : new Warehouse();
        w.Name = dto.Name;
        _dao.SaveOrUpdate(w);
        return new SaveResponse
                   {
                       Data = new InsertData
                                  {
                                      Id = w.Id
                                  }
                   };
    }

I need the thrown Exception for the Transaction to be rolled back, so i cannot actually catch it and return something else.

Any ideas, where I could hook in?

© Stack Overflow or respective owner

Related posts about wcf

Related posts about castle-windsor