代码之家  ›  专栏  ›  技术社区  ›  Chris Stewart

从wcf4rest模板获取调试输出

  •  1
  • Chris Stewart  · 技术社区  · 14 年前

    我试图查看在我的WCF服务中抛出的异常,但我从响应中得到的只有:

    “由于内部错误,服务器无法处理请求。有关错误的详细信息,请在服务器上启用IncludeExceptionDetailInFaults(从ServiceBehaviorAttribute或从配置行为)以将异常信息发送回客户端,或者根据Microsoft.NET Framework 3.0 SDK文档打开跟踪并检查服务器跟踪日志。“

    1 回复  |  直到 14 年前
        1
  •  0
  •   JoshKraker    14 年前

    我想到的是:

    在您的web.config文件,启用faultExceptionEnabled

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

    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>
    

    希望这有帮助。