打开IncludeExceptionDetailInFaults?

时间:2013-07-11 16:49:38

标签: c# asp.net asp.net-mvc wcf asp.net-mvc-4

我的WCF服务抛出异常。无法找到异常可能是什么。

它像这样抛出

System.ServiceModel.FaultException: The server was unable to process the request
due to an internal error. For more information about the error, either turn on
IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the
configuration behavior) on the server in order to send the exception information 
back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK 
documentation and inspect the server trace logs.

的web.config

<system.serviceModel>
<services>
  <service name="ServiceName" behaviorConfiguration="debug" />
</services>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_ITwoWayAsync" />
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="http://company.com/CustCommPreferences.svc" 
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITwoWayAsync" 
            contract="OptInOutServices.CustCommPreferences" name="BasicHttpBinding_ITwoWayAsync" />
</client>
<behaviors>
  <serviceBehaviors>
    <behavior name="debug">
      <serviceDebug includeExceptionDetailInFaults="true" />
      <serviceMetadata httpGetEnabled="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

看起来我也添加了ServiceDebug,但我仍无法找到内部异常或堆栈跟踪

catch (FaultException ex)
 {
    string msg = "FaultException: " + ex.Message;
    MessageFault fault = ex.CreateMessageFault();
    if (fault.HasDetail == true)
    {
       System.Xml.XmlReader reader = fault.GetReaderAtDetailContents();
       if (reader.Name == "ExceptionDetail")
       {
          ExceptionDetail detail = fault.GetDetail<ExceptionDetail>();
          msg += "\n\nStack Trace: " + detail.StackTrace;
       }
    }
    return View("Error");

   }

0 个答案:

没有答案