0

サーバーがクライアントからの情報を要求する状況があります。

コールバック宣言:

public interface IControlServiceCallback
{
    [...]

    [OperationContract]
    [FaultContract(typeof(GetSystemFilesFault))]
    List<SystemFile> GetSystemFiles(string directory);
}

コールバックの実装:

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));
    }
}

問題は、メソッドを呼び出してFaultException<TDetail>クライアント側でスローすると、例外が正しく処理されないことです。CommunicationException代わりに 以下の図のように。

ここに画像の説明を入力

問題を切り分けることができるかどうかを確認するために、いくつかの WCF ログ機能を使用しようとしましたが、サーバーが応答を受信するとすぐに例外がスローされます。

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;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

この動作の原因は何ですか? 私のコードはcatch (FaultException<FaultBase> e)ブロックに入るべきではありませんか?

まず、どうすれば問題を見つけることができますか?

編集:

コールバック メソッドが void を返す限り、例外が正しくキャッチされていることがわかりました。コールバックの設定に関係している可能性があります。

4

0 に答える 0