【发布时间】:2018-02-02 13:00:48
【问题描述】:
我用 WCF 做了一些测试,但我不确定一件事。
我有以下服务:
[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)?
【问题讨论】:
标签: c# wcf asynchronous task