C# 当includeExceptionDetailInFaults=”时返回自定义错误消息;假;
我将.net svc服务与.net framework 4.5一起使用,出于生产目的,我必须在我的C# 当includeExceptionDetailInFaults=”时返回自定义错误消息;假;,c#,.net,exception,svc,C#,.net,Exception,Svc,我将.net svc服务与.net framework 4.5一起使用,出于生产目的,我必须在我的web.config文件中将includeExceptionDetailInFaults设置为false 但是,有时我需要服务返回自定义错误 我尝试使用System.ServiceModel.Dispatcher.IErrorHandler.ProvideFault方法创建自定义FaultException,但没有结果,返回的错误消息始终是一般消息 有可能吗?如果是,如何 谢谢是的,可以返回自定义错
web.config
文件中将includeExceptionDetailInFaults
设置为false
但是,有时我需要服务返回自定义错误
我尝试使用System.ServiceModel.Dispatcher.IErrorHandler.ProvideFault
方法创建自定义FaultException
,但没有结果,返回的错误消息始终是一般消息
有可能吗?如果是,如何
谢谢是的,可以返回自定义错误消息。 只需将消息包装在FaultException中:
try
{
// some calls go here
}
catch (Exception ex)
{
throw new FaultException(ex.Message);
}
当发生错误时,调用您的服务的客户端将看到一条清晰的消息,而不是异常详细信息