クライアントから WCF サービスへの非同期呼び出しを行っています。サービスが FaultException 例外をスローしています。クライアントの "Completed" イベント ハンドラーで例外をキャッチすると、例外はキャッチされますが、それに関するすべての情報が失われます。私が得るのは、「CommunicationException: リモートサーバーがエラーを返しました: NotFound」) というエラーメッセージを持つジェネリック型の例外だけです。includeExceptionDetailInFaults を true に設定しました。
FaultException をキャッチできないのはなぜですか?
ご協力ありがとうございました。
関連するコードは次のとおりです。
WCF サービス コード
[WebMethod]
[FaultContract(typeof(DivideByZeroException))]
public int CountResults(FilterArgs args)
{
...
DivideByZeroException divByZero = new DivideByZeroException();
throw new FaultException<DivideByZeroException>(divByZero);
クライアントコード
void seasClient_CountResultsCompleted(object sender, CountResultsCompletedEventArgs e)
{
try
{
...
}
catch (FaultException ex)
{
MessageBox.Show("FaultException" + ex.Message);
}
catch (TimeoutException ex)
{
MessageBox.Show("TimeoutException" + ex.Message);
}
catch (CommunicationException ex)
{
MessageBox.Show("CommunicationException" + ex.Message);
}
catch (Exception ex)
{
MessageBox.Show("Exception" + ex.Message);
}
そして私の e.Error.ToString() メッセージ:
System.ServiceModel.CommunicationException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound.
at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClassa.<EndGetResponse>b__9(Object sendState)
at System.Net.Browser.AsyncHelper.<>c__DisplayClass4.<BeginOnUI>b__0(Object sendState)
--- End of inner exception stack trace ---
at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)
--- End of inner exception stack trace ---
at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result)
at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
at System.ServiceModel.ClientBase`1.ChannelBase`1.EndInvoke(String methodName, Object[] args, IAsyncResult result)
at WebAnalysis.SeasService.SeasServiceSoapClient.SeasServiceSoapClientChannel.EndCountResults(IAsyncResult result)
at WebAnalysis.SeasService.SeasServiceSoapClient.WebAnalysis.SeasService.SeasServiceSoap.EndCountResults(IAsyncResult result)
at WebAnalysis.SeasService.SeasServiceSoapClient.EndCountResults(IAsyncResult result)
at WebAnalysis.SeasService.SeasServiceSoapClient.OnEndCountResults(IAsyncResult result)
at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result)