简体   繁体   English

WCF方法调用开始和结束是否有事件?

[英]Are there events for WCF method call start and finish?

I am producing a WPF application using a WCF service to feed it data. 我正在使用WCF服务提供数据来生产WPF应用程序。 Normal boring stuff. 正常的无聊的东西。 I am not using RIA. 我没有使用RIA。

I have a global view model, in which I maintain just one reference to the service client object I use for all service calls. 我有一个全局视图模型,在该模型中,我仅维护对用于所有服务调用的服务客户端对象的一个​​引用。 I have a little screen blocker to stop users from interacting with the application while it waits for important data. 我有一个小小的屏幕阻止程序,可在用户等待重要数据时阻止用户与该应用程序进行交互。 I would like this to be automated across my entire application. 我希望在整个应用程序中实现自动化。 So I am looking for events on the service client (or its inner channel) to hook into so I can automatically do this. 因此,我正在寻找服务客户端(或其内部通道)上的事件以进行跟踪,以便可以自动执行此操作。

So far I've not found them. 到目前为止,我还没有找到它们。 The closest I've got are the completed events of each method exposed by the web service - but nothing for when the methods are called. 我得到的最接近的是Web服务公开的每个方法的完成事件-但是调用方法时没有任何事件。 I did some WPF/WCF work a few years back and I managed to make this work but I cannot remember how. 几年前,我做了一些WPF / WCF的工作,我设法完成了这项工作,但我不记得如何做。 Does anyone know the secret? 有人知道这个秘密吗?

I would create a proxy of the proxy. 我将创建代理的代理。 The new proxy would basically wrap each call: raise a starting event, call actual method, raise an ending event. 新的代理基本上将包装每个调用:引发一个开始事件,调用实际方法,引发一个结束事件。 With a little help of something that could create such proxy for you, this could be easy. 在一些可以为您创建此类代理的东西的帮助下,这可能很容易。 Castle.DynamicProxy should do the trick. Castle.DynamicProxy应该可以解决问题。

You can create a class that implements IClientMessageInspector and register it by using a behavior. 您可以创建一个实现IClientMessageInspector的类,并使用行为对其进行注册。 See this post for a great answer. 看到这个帖子的一个很好的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM