当我们从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>
错误: -
答案 0 :(得分:0)
您无法直接从WCF登录到HTML(或者更确切地说,您可以但不应该)。
你可以做的是抛出一个带有适当消息的FaultException
并让你的ASP.NET页面处理Exception
并使用适当的Exception.Message
呈现一个HTML页面(我更喜欢) Exception.ToString()
)。
有关详细信息,请查看此链接:Fault Handling in WCF Services