Hi,

I've got an MVC web application, and I'm calling a WCF service from one of 
my controllers. The controller method returns a JSON result, and does 
something like the following:

public ActionResult GetItem(string key)
{
    object result;

    try
    {
        result = wcfClient.GetItem(key);
    }
    catch (Exception e)
    {
        result = new { Exception = e.ToString() };
    }

    return Json(result, JsonRequestBehavior.AllowGet);
}

My WCF client is registered as follows:

container.Register(
                Component.For<ICacheService>()
                    
.AsWcfClient(WcfEndpoint.FromConfiguration("CacheService"))
                    .LifestylePerWebRequest());

The reason I have the try-catch in the controller method is that this is an 
internal service for developers to use, so if there's some kind of problem, 
I just want to display it on the page.

My issue is that when the request ends, Windsor tries to dispose the client 
proxy. Because an exception was thrown by the client, the WCF channel is 
now in a faulted state. This means that when Dispose() is called, another 
exception ends up being thrown because you can't call methods when the 
channel is in a faulted state. This means that even though I've handled the 
exception in my controller, I can't actually return the result because the 
request fails after it's gone out of my control.

I've got a workaround for this which is to just not handle the exception, 
and display the error message returned by the web server, but it does seem 
wrong to me that the component gets disposed when it's in a state where 
disposing it causes an exception to be thrown.

Is this a bug, or am I doing something wrong?

Cheers,
Adam

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/castle-project-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to