-1
我正在從客戶端向WCF服務進行異步調用。該服務拋出FaultException異常。當我在我的Client「Completed」事件處理程序中捕獲異常時,它捕獲異常,但丟失了有關它的所有信息。我所得到的是一個泛型類型的異常,帶有此錯誤消息:「CommunicationException:遠程服務器返回錯誤:NotFound」)。我有includeExceptionDetailInFaults設置爲true。WCF拋出FaultException,客戶端捕獲異常但丟失所有信息
爲什麼我不能捕捉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)
謝謝約翰。我顯然是一個新手,我繼承了這個代碼。 – mschu