简体   繁体   中英

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

We have developed the wcf service,when we are calling web service from WCF Test Client to fetch the data, In this case we are getting some exception while calling the WCF web service. I want to log error into html file.

My Code:-

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

Web Config :-

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

Error :-

在此处输入图片说明

You can't log directly from WCF into HTML (or rather, you could but shouldn't).

What you could rather do is throw a FaultException with an appropriate message and have your ASP.NET page handle the Exception and render an HTML page with the appropriate Exception.Message (I prefer Exception.ToString() ) in it.

For more information have a look at this link: Fault Handling in WCF Services

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM