问题描述
我有一个执行操作的wcf服务。在此操作中可能会出现故障。我已经说过我的服务合同可能有问题。
i have a wcf service that does an operation. and in this operation there could be a fault. i have stated that there could be a fault in my service contract.
这是下面的代码;
public void Foo()
{
try
{
DoSomething(); // throws FaultException<FooFault>
}
catch (FaultException)
{
throw;
}
catch (Exception ex)
{
myProject.Exception.Throw<FooFault>(ex);
}
}
在服务合同中;
[FaultException(typeof(FooFault))]
void Foo();
当我在运行应用程序时,DoSomething()方法抛出了FaultException时,首先是在 catch(Exception ex)行捕获并在那里中断。然后当我再次按f5键时,它通常会执行该操作。我不知道为什么会有这种突破?
when a FaultException was thrown by DoSomething() method while i was running the application, firstly the exception was caught at "catch(Exception ex)" line and breaks in there. then when i pressed f5 again, it does what normally it has to. i wonder why that break exists? and if not could it be problem on publish?
推荐答案
您是否正在使用Silverlight中的WCF服务?如果是这样,则需要进行特殊配置以使服务返回HTTP 200代码(如果出现错误,则返回500)。详细信息在这里:
Are you consuming the WCF service from Silverlight? If so, a special configuration is needed to make the service return a HTTP 200 code instead of 500 in case of error. The details are here: http://msdn.microsoft.com/en-us/library/dd470096%28VS.96%29.aspx
这篇关于无法处理FaultException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!