WCF Webservice - 无法调用服务。该服务处于脱机状态或无法访问

时间:2014-08-30 04:58:53

标签: c# asp.net web-services wcf

当我们从WCF测试客户端调用Web服务来获取数据时,我们已经开发了wcf服务。在这种情况下,我们在调用WCF Web服务时遇到了一些异常。我想将错误记录到html文件中。

我的代码: -

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

Web配置: -

 <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>

错误: -

enter image description here

1 个答案:

答案 0 :(得分:0)

您无法直接从WCF登录到HTML(或者更确切地说,您可以但不应该)。

你可以做的是抛出一个带有适当消息的FaultException并让你的ASP.NET页面处理Exception并使用适当的Exception.Message呈现一个HTML页面(我更喜欢) Exception.ToString())。

有关详细信息,请查看此链接:Fault Handling in WCF Services