【发布时间】:2011-01-28 18:20:24
【问题描述】:
我有一个抛出异常的 WCF 服务,我试图在我的 silverlight 客户端代码中捕获该异常但未成功。我正在使用未声明的故障进行调试,这是我的服务方法:
[OperationContract]
public ServiceResponse MyWCFServiceMethod()
{
ServiceResponse resp = new ServiceResponse ();
//code for setting resp...
//purposely throw error here.
throw new FaultException(new FaultReason(new FaultReasonText("My fault Reason!")),new FaultCode("my fault code here"));
return resp;
}
现在在我的 silverlight 客户端视图模型中,在服务的回调方法中,我尝试像这样处理它:
private void MyServiceCallback(MyWCFServiceMethodCompletedEventArgs e)
{
if (e.Error == null)
{
//proceed normally
}
else if (e.Error is FaultException)
{
FaultException<ExceptionDetail> fault = e.Error as FaultException<ExceptionDetail>;
MessageBox.Show(fault.Detail.Message);
MessageBox.Show(fault.Reason.ToString());
}
}
在这一行 else if (e.Error is FaultException) 我仍然得到 System.Net.WebException {远程服务器返回错误:NotFound.}
这些是配置条目
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
这是服务类声明
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class MySilverlightWCFService
{
....
此服务位于同一 silverlight 解决方案中的另一个项目中。 为什么我的 silverlight 客户端无法获取我抛出的错误异常?
感谢您的宝贵时间...
【问题讨论】:
标签: silverlight wcf faultexception