簡體   English   中英

WCF Web服務-無法調用服務。 服務離線或無法訪問

[英]WCF Webservice - Failed to invoke the service. The service is offline or inaccessible

當我們從WCF測試客戶端調用Web服務以獲取數據時,我們已經開發了wcf服務。在這種情況下,調用WCF Web服務時會遇到一些異常。 我想將錯誤記錄到html文件中。

我的代碼:

        try
        {
            int i = 1;
            int j = 0;
            int k = i / j;
        }
        catch (Exception ex)
        {
            ApplicationError.LogErrors(ex);
        }

網絡配置

 <appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
 <system.web>
<compilation debug="true" targetFramework="4.5"/>
</system.web>
<system.serviceModel>
 <behaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"     multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<handlers>
  <remove name="ISAPI-dll"/>
  <add name="ISAPI-dll" path="*.dll" verb="*" modules="IsapiModule"   scriptProcessor="C:\WINDOWS\System32\inetsrv\asp.dll" resourceType="File" requireAccess="None" allowPathInfo="true" preCondition="bitness64"/>
</handlers>
<directoryBrowse enabled="false"/>
</system.webServer>

錯誤:-

在此處輸入圖片說明

您不能直接從WCF登錄到HTML(或者可以,但是不應該)。

您更願意做的是拋出一個帶有適當消息的FaultException ,並讓您的ASP.NET頁處理該Exception並在其中呈現一個具有適當Exception.Message (我更喜歡Exception.ToString() )的HTML頁面。

有關更多信息,請參見以下鏈接: WCF服務中的錯誤處理

暫無
暫無

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

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