WCF 客户端对象反序列化通知
我有一个 WPF 客户端应用程序通过对远程 WCF 服务的引用接收对象。 WCF 服务引用是通过 Visual Studio 的“添加服务引用...”生成的。
我想在每次从 WCF 服务接收/反序列化对象时执行一段代码。该对象需要已经被反序列化,以便我可以读取其属性/调用方法。该解决方案将是全局的,不需要我添加到每个 WCF 服务调用中。
I have a WPF client application receiving objects via a reference to a remote WCF service. The WCF service references were generated via Visual Studio's 'Add Service Reference...'.
I would like to execute a piece of code each time an object received/deserialized from the WCF service. The object needs to already be deserialized so I can read properties/call methods on it. This solution would be global and not something I need to add to every WCF service call.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从迈克的最初反应开始,我想出了以下解决方案。
后台
预警
我知道这会破坏一些面向对象和责任规则,但是该解决方案是如此简短、如此简单,并且适合我当前和预期的未来需求,所以这就是我所采用的。当每个客户端反序列化都需要发生重要逻辑时,此解决方案不太实用。
按键
动态关键字,因为包含DTO的项目无法引用
UI项目由于循环引用。如果它无法引用 UI 项目,则编译器不知道 IsAnythingDirty 布尔值。
Starting with Mike's initial response I was able to come up with the following solution.
Background
Forewarning
I understand that this breaks some object oriented and responsibility rules, however the solution is so short, so easy, and fits my current and anticipated future needs so it is what I went with. This solution is less practical when there is significant logic that needs to occur on each client-side deserialization.
The keys
dynamic keyword because the project containing the DTO cannot reference the
UI project due to a circular reference. If it can't reference the UI project the compiler does not know about the IsAnythingDirty boolean.
您可以使用 OnDeserialized 属性:
http://msdn。 microsoft.com/en-us/library/system.runtime.serialization.ondeserializedattribute.aspx
You could use the OnDeserialized attribute:
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.ondeserializedattribute.aspx