簡體   English   中英

在服務器上啟用IncludeExceptionDetailInFaults(來自ServiceBehaviorAttribute或來自<serviceDebug>配置行為)

[英]Turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server

我有一個完美的WCF服務,有些東西已經改變,我不知道是什么。

我得到這個例外:

System.ServiceModel.FaultException:由於內部錯誤,服務器無法處理請求。 有關錯誤的更多信息,請在服務器上啟用IncludeExceptionDetailInFaults(來自ServiceBehaviorAttribute或配置行為)以將異常信息發送回客戶端,或者根據Microsoft .NET Framework 3.0 SDK文檔啟用跟蹤並檢查服務器跟蹤日志。

這很令人困惑,因為我正在運行.NET 4.0。

我在哪里打開IncludeExceptionDetailInFaults 我正在努力尋找它。

.config文件中定義行為

<configuration>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="debug">
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    ...
  </system.serviceModel>
</configuration>

然后沿着以下行將行為應用於您的服務:

<configuration>
  <system.serviceModel>
    ...
    <services>
      <service name="MyServiceName" behaviorConfiguration="debug" />
    </services>
  </system.serviceModel>
</configuration>

您也可以通過編程方式進行設置。 看到這個問題

它位於app.config文件中。

<configuration>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceDebug includeExceptionDetailInFaults="true"/>

如果您想通過代碼執行此操作,可以添加如下行為:

serviceHost.Description.Behaviors.Remove(
    typeof(ServiceDebugBehavior));
serviceHost.Description.Behaviors.Add(
    new ServiceDebugBehavior { IncludeExceptionDetailInFaults = true });

您也可以在繼承接口的類聲明上方的[ServiceBehavior]標記中進行設置

[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class MyClass:IMyService
{
...
}

Immortal Blue在公開發布的版本中沒有公開exeption詳細信息是正確的,但出於測試目的,這是一個方便的工具。 釋放時始終關閉。

我也得到了相同的錯誤,當我在Dev環境中使用我的憑據時,WCF正在為我正常工作,但是當其他人在TEST中使用它時,它會拋出相同的錯誤。 我做了很多研究,然后在沒有進行配置更新的情況下,在故障異常的幫助下在WCF方法中處理了一個異常。 此外,WCF的標識需要使用在數據庫中具有訪問權限的相同憑據進行設置,有人可能已經更改了您的權限。 請在下面找到相同的代碼:

 [ServiceContract]
public interface IService1
{
    [OperationContract]
    [FaultContract(typeof(ServiceData))]
    ForDataset GetCCDBdata();

    [OperationContract]
    [FaultContract(typeof(ServiceData))]
    string GetCCDBdataasXMLstring();


    //[OperationContract]
    //string GetData(int value);

    //[OperationContract]
    //CompositeType GetDataUsingDataContract(CompositeType composite);

    // TODO: Add your service operations here
}

  [DataContract]
public class ServiceData
{
    [DataMember]
    public bool Result { get; set; }
    [DataMember]
    public string ErrorMessage { get; set; }
    [DataMember]
    public string ErrorDetails { get; set; }
}

在service1.svc.cs中,您可以在catch塊中使用它:

 catch (Exception ex)
        {
            myServiceData.Result = false;
            myServiceData.ErrorMessage = "unforeseen error occured. Please try later.";
            myServiceData.ErrorDetails = ex.ToString();
            throw new FaultException<ServiceData>(myServiceData, ex.ToString());
        }

並在客戶端應用程序中使用此代碼如下代碼:

  ConsoleApplicationWCFClient.CCDB_HIG_service.ForDataset ds = obj.GetCCDBdata();

            string str = obj.GetCCDBdataasXMLstring();

        }

        catch (FaultException<ConsoleApplicationWCFClient.CCDB_HIG_service.ServiceData> Fex)
      {
          Console.WriteLine("ErrorMessage::" + Fex.Detail.ErrorMessage + Environment.NewLine);
          Console.WriteLine("ErrorDetails::" + Environment.NewLine + Fex.Detail.ErrorDetails);
          Console.ReadLine();
      }

試試這個,它將有助於確保獲得確切的問題。

由於首先說錯誤信息,請嘗試增加客戶端和服務端的超時值,如下所示:

<basicHttpBinding>
    <binding name="basicHttpBinding_ACRMS" maxBufferSize="2147483647"
      maxReceivedMessageSize="2147483647"
      openTimeout="00:20:00" 
      receiveTimeout="00:20:00" closeTimeout="00:20:00"
      sendTimeout="00:20:00">
      <readerQuotas maxDepth="32" maxStringContentLength="2097152"
        maxArrayLength="2097152" maxBytesPerRead="4006" maxNameTableCharCount="16384" />
    </binding>

那么請不要忘記通過執行以下操作將此綁定配置應用於端點:

<endpoint address="" binding="basicHttpBinding" 
      bindingConfiguration="basicHttpBinding_ACRMS"
      contract="MonitorRAM.IService1" />

如果以上情況無濟於事,那么如果您可以嘗試在此處上傳您的主項目會更好,那么我想在我身邊進行測試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM