在两个应用程序之间传递异常数据 [英] Passing exception data between two applications
问题描述
我不知道这是否已经回答。但是,我找不到该问题的示例或原因。
I don't know if this has been already answered or not. But, I am unable to find the example or cause of this problem.
应用程序1:
try
{
//Read request and check for the request header element from the soap request
//validating request and salt
...here it might gets failed.
_requestValidationService.ValidateRequest();
}
catch (Exception ex)
{
ex.Data.Add("Exception", "test");
throw ex;
}
应用程序2:
catch (Exception ex)
{
string aa = Convert.ToString(ex.Data["Exception"]);
throw ex;
}
我不知道我在这里想念的是什么。但是 aa 似乎总是空的,而 ex.Data.Count
总是零。
I don't know what I am missing here. But aa seems to be always empty and ex.Data.Count
is always zero.
我只想在两个应用程序之间传递一个代码,而不添加异常的新类。
I just want to pass one code between two applications without adding new class of an exception.
注意:这两个应用程序是wcf调用。
Note: These two applications are wcf calls.
应用程序1验证请求是 IDispatchMessageInspector
AfterReceiveRequest
Application 1 validate request is the IDispatchMessageInspector
AfterReceiveRequest
推荐答案
异常不会从WCF服务传播到客户端。而是将SOAP错误(假设您正在使用SOAP)发送给客户端。
Exceptions are not propagated to clients from a WCF service. Instead, a SOAP Fault (assuming you are using SOAP) will be sent to the client.
您可以在SOAP Fault中包括异常详细信息,但通常不建议在生产环境中这样做。
You can include exception details in the SOAP Fault, but in general it is not recommended to do so in production.
恕我直言,更好的方法是实施一个IErrorHandler ,可以为Fault提供要发送给客户端的任何数据,并为您提供记录异常服务器端的机会。
IMHO a better approach is to implement an IErrorHandler that provides the Fault with whatever data you want to send to the client, and also gives you the opportunity to log the exception server-side.
然后您可以在客户端上捕获 FaultException
,并可以访问自定义错误处理程序添加的数据。
You can then catch FaultException
on the client and have access to the data added by your custom error handler.
这篇关于在两个应用程序之间传递异常数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!