注意我已经看到这些列表here
try
{
// Some code......
}
catch (CommunicationException exception) // WCF Exception
{
}
catch (TimeoutException exception) // WCF Exception -
{
}
catch (Exception ex)
{
// Standard exception
}
答案 0 :(得分:1)
在WCF客户端中,您可以捕获从捕获FaultException的服务抛出的异常。如果需要特殊处理(即TimeoutException或CommunicationException),也可以捕获任何其他类错误。
以下是一个例子:
proxy ServiceClient();
try
{
proxy = new ServiceClient();
proxy.DoSomething();
}
catch (FaultException ex)
{
// handle errors returned by WCF service
}
catch (CommunicationException ex)
{
// handle communication errors here
}
catch (TimeOutException ex)
{
// handle timeouts here
}
catch (Exception ex)
{
// handle unaccounted for exception here
}
finally
{
if (proxy.State == CommunicationState.Opened)
{
proxy.Close();
}
else
{
proxy.Abort();
}
}