【问题标题】:WCF Webservice - Failed to invoke the service. The service is offline or inaccessibleWCF Webservice - 无法调用服务。服务离线或无法访问
【发布时间】:2014-08-30 04:58:53
【问题描述】:

我们已经开发了 wcf 服务,当我们从 WCF 测试客户端调用 web 服务来获取数据时,在这种情况下,我们在调用 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>

错误:-

【问题讨论】:

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


    【解决方案1】:

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

    你宁愿做的是抛出一个带有适当消息的FaultException,让你的ASP.NET页面处理Exception,并在其中呈现一个带有适当Exception.Message的HTML页面(我更喜欢Exception.ToString()) .

    欲了解更多信息,请查看此链接:Fault Handling in WCF Services

    【讨论】:

      猜你喜欢
      • 2013-06-11
      • 1970-01-01
      • 2016-01-07
      • 2012-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多