我有以下课程实现我的服务
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class CatalogueService : ICatalogueService
在一种方法中,我抛出FaultException
:
public List<ProductType> GetProductType()
{
bool isThrow = true;
if (isThrow)
throw new FaultException(new FaultReason(new FaultReasonText("My fault Reason!")), new FaultCode("my fault code here"));
else
{
.......
}
}
在文件后面的Silverlight代码中,我试图在FaultException
事件中显示Async Completed
消息:
void service_GetProductTypeCompleted(object sender, GetProductTypeCompletedEventArgs e)
{
if (e.Error == null)
{
pType = e.Result.ToList();
cboProductType.DataContext = pType;
}
else
{
FaultException fault = e.Error as FaultException;
MessageBox.Show(fault.Reason.ToString());
}
}
但问题不在于抛出FaultException
投掷CommunicationException
。我做错了什么?
修改
同样在MessageBox.Show(fault.Reason.ToString());
我得到NullReferenceException
对象引用未设置为对象的实例。