2010-10-20 68 views
1

我想看到的是在我的WCF服务抛出的异常,但所有我从响应得到的是:输出获取调试

“服务器无法请求过程中因一个内部错误有关错误的更多信息,请在服务器上打开IncludeExceptionDetailInFaults(来自ServiceBehaviorAttribute或来自配置行为),以便将异常信息发送回客户端,或者根据Microsoft .NET打开跟踪Framework 3.0 SDK文档并检查服务器跟踪日志。“

因为我这样做的“休息”的方式,我没有这些选项在我的web.config。那么,如何在使用WCF 4 REST模板时启用“IncludeExceptionDetailInFaults”?

+0

你有没有运气得到这个工作? 我有服务工作,但POSTS失败,除非我接受Stream对象,而不是DataContract。 – 2011-01-30 21:52:14

+0

为了获得这些错误,我只是简单地将它们引入服务中,并将它们写入本地文件。我永远无法让他们通过网络浏览器回来并远程显示。 – 2011-02-01 19:47:14

回答

0

这就是我想出了:

下standardEndpoint在你的web.config,打开faultExceptionEnabled

<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" faultExceptionEnabled="true"> 

然后,自定义消息显示,在抛出的异常必须是一个FaultException异常。这里有一个,我使用的例子:

if (!Enum.GetNames(typeof(Models.Games.GsfCurrencyPrice.Sections)).Contains(section)) throw new FaultException<ArgumentException>(new ArgumentException("Value must be one of the following: " + string.Join(", ", Enum.GetNames(typeof(Models.Games.GsfCurrencyPrice.Sections))), "section")); 

抛出时产生以下反应:

<Fault xmlns="http://schemas.microsoft.com/ws/2005/05/envelope/none"><Code><Value>Sender</Value></Code><Reason><Text xml:lang="en-US">The creator of this fault did not specify a Reason.</Text></Reason><Detail><ArgumentException xmlns="http://schemas.datacontract.org/2004/07/System" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:x="http://www.w3.org/2001/XMLSchema"><ClassName i:type="x:string" xmlns="">System.ArgumentException</ClassName><Message i:type="x:string" xmlns="">Value must be one of the following: Buy, Sell</Message><Data i:nil="true" xmlns=""/><InnerException i:nil="true" xmlns=""/><HelpURL i:nil="true" xmlns=""/><StackTraceString i:nil="true" xmlns=""/><RemoteStackTraceString i:nil="true" xmlns=""/><RemoteStackIndex i:type="x:int" xmlns="">0</RemoteStackIndex><ExceptionMethod i:nil="true" xmlns=""/><HResult i:type="x:int" xmlns="">-2147024809</HResult><Source i:nil="true" xmlns=""/><WatsonBuckets i:nil="true" xmlns=""/><ParamName i:type="x:string" xmlns="">section</ParamName></ArgumentException></Detail></Fault> 

希望这有助于。