WCF 服务器中的本地化
我非常熟悉在简单的 WPF UI 应用程序中使用本地化。
我现在正在开发 WCF 客户端/服务器架构;我希望能够在服务器中创建各种类型的异常,并在客户端的文化中显示错误消息。
这看起来很简单 - 我们将通过某种方式识别特定 WCF 客户端当时使用的文化。
但是,我希望这些消息也可能以一种语言(通常是英语)记录到服务器的日志文件中,以便更轻松地支持应用程序。
服务器端和客户端都使用了各种组件;每个程序集都有一个错误消息字符串表。因此,当创建异常时,需要掌握该给定程序集的资源 ID 和资源管理器。如果不对每个可用的异常类型进行子类化,我无法看到如何解决这个问题。对于以前肯定遇到过的问题,这似乎需要大量工作?
示例
Server.A.dll
Error Resources: MyErrorString1, MyErrorString2
Resource Manager: ResourceManagerA
Server.B.dll
Error Resources: MyErrorString3
Resource Manager: ResourceManagerB
因此,理想情况下,我需要在需要将消息记录到文件或将其发回时访问给定字符串的资源管理器将 WCF 视为故障;但我不想失去通过使用一个通用异常类来捕获异常类型的能力。
有谁对这个问题有任何经验,或者对如何实施它有任何很酷的建议?
预先感谢,
史蒂夫
I am fairly well versed in using localization in a simple WPF UI application.
I am now in the process of developing a WCF client/server architecture; I want to be able to create various types of exception in the server, and have the error message in the culture of the client.
This seems straightforward enough - somehow we will identify the culture being used by the particular WCF client at the time.
However, I want the messages to potentially also be logged into the server's logfile in one language (typically English) to allow easier support of the application.
There are various assemblies used in both the server and the client side; each assembly is going to have a string table of error messages. Therefore when an exception is created, it needs to have the resource ID and the resource manager for that given assembly to hand. Without sub-classing each available exception type, I cannot see how to get around this. This seems like a lot of work for a problem that has surely been encountered before?
Example
Server.A.dll
Error Resources: MyErrorString1, MyErrorString2
Resource Manager: ResourceManagerA
Server.B.dll
Error Resources: MyErrorString3
Resource Manager: ResourceManagerB
So ideally I need to have access to the resource manager for a given string at the time I need to either log the message to the file or send it back over WCF as a fault; but I don't want to lose the ability to catch types of exceptions by using one generic exception class.
Does anyone have any experience of this problem, or any cool suggestions on how to go about implementing it?
Thanks in advance,
Steve
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为向用户显示简单的异常消息不是个好主意。相反,我会抓住他们记录它们并在用户界面中显示友好的消息。这样你就不需要子类化任何东西......
I don't think that is good idea to show plain Exception messages to users. Instead, I would catch them log them and show friendly message in UI. That way you won't need to subclass anything...
如果是技术异常,则无需用户无论如何都无法理解的细节。仅显示一般错误消息。
至于预期的错误情况,应该将它们编入某个地方。然后,您只需在客户端和服务器之间交换错误代码,并根据错误代码在客户端进行本地化即可。
If it is a technical exception, there is no need for details that the user won't understand anyway. Just display a generic error message.
As for expected error condition, they should be cataloged somewhere. Then you just need to exchange error codes between client and server and do the localization on the client based on the error code.