I have a situation where the server requests information from the client.
Callback declaration:
public interface IControlServiceCallback
{
[...]
[OperationContract]
[FaultContract(typeof(GetSystemFilesFault))]
List<SystemFile> GetSystemFiles(string directory);
}
Callback implementation:
public List<SystemFile> GetSystemFiles(string directory)
{
try
{
var files = Directory.GetDirectories(directory)
.Select(x => new DirectoryInfo(x))
.Select(x => new SystemFile(x)).ToList();
files.AddRange(Directory.GetFiles(directory)
.Select(x => new FileInfo(x))
.Select(x => new SystemFile(x)));
return files;
}
catch (UnauthorizedAccessException e)
{
throw new FaultException<GetSystemFilesFault>(new GetSystemFilesFault(e));
}
catch (Exception e)
{
throw new FaultException<GetSystemFilesFault>(new GetSystemFilesFault(e));
}
}
The problem is that when I make the call do the method and it throws a FaultException<TDetail>
on the client side, the exception in not handled correctly. I get a CommunicationException
instead. As illustrated bellow.
I tried to use some WCF logging functionality to see if I could isolate the problem, but the exception is being thrown as soon as the server receives the response.
Server stack trace:
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp; msgData, Int32 type)
at RemoteControl.Service.IControlServiceCallback.GetSystemFiles(String directory)
at RemoteControl.Service.Objects.Handling.ControlServiceCallbackProxy.GetSystemFiles(String directory) in c:\Users\Bruno\Source\Repos\RemoteControl\RemoteControl\RemoteControl.Service\Objects\Handling\ControlServiceCallbackProxy.cs:line 46
at RemoteControl.Host.Controllers.ClientController.SelectedDirectoryChanged(String path) in c:\Users\Bruno\Source\Repos\RemoteControl\RemoteControl\RemoteControl.Host\Controllers\ClientController.cs:line 41
at RemoteControl.Host.Forms.ClientForm.treeList_DoubleClick(Object sender, EventArgs e) in c:\Users\Bruno\Source\Repos\RemoteControl\RemoteControl\RemoteControl.Host\Forms\ClientForm.cs:line 95
What could be causing this behavior? Shouldn't my code be getting into the catch (FaultException<FaultBase> e)
block?
Foremost, how could I find the issue?
Edit:
I just discovered that the exceptions are being catched correctly, as long as the callback method returns void. It may have something to do with my callback setup.