0
我用WCF做了一些測試,我不確定要理解一件事。爲什麼WCF異步方法在同步時不會拋出FaultException?
我以下服務:
[ServiceContract]
public interface ICommunicationIssuesService:IService
{
[OperationContract]
void TestExceptionInActionSync();
[OperationContract]
Task TestExceptionInActionAsync();
}
與下面的實現:
public class CommunicationIssuesService : ICommunicationIssuesService
{
public void TestExceptionInActionSync()
{
throw new InvalidOperationException();
}
public async Task TestExceptionInActionAsync()
{
throw new InvalidOperationException();
}
}
在客戶端,我創建的ChannelFactory,然後在其上:
//Test Synchronous
//... Setup of the channelFactory
ICommunicationIssuesService channel =_channelFactory.CreateChannel()
try{
channel.TestExceptionInActionSync();
}catch(FaultException<ExceptionDetail>){
//I receive an FaultException
}
//Test Asynchronous
//... Setup of the channelFactory
ICommunicationIssuesService channel =_channelFactory.CreateChannel()
try{
channel.TestExceptionInActionAsync();
}catch(AggregateException){
//I receive an AggregateException, I guess because it's a Task behind
}
我不明白的是爲什麼我在這裏沒有收到FaultException(或AggregateException)?