开发者

Trigger event from ChannelFactory

开发者 https://www.devze.com 2023-04-04 15:36 出处:网络
We are using the ChannelFactory to connect to our WCF Service. When ever I do a call to the service, I want the Channel f开发者_如何学编程actory to trigger another event. Something like \'OnFunctionCa

We are using the ChannelFactory to connect to our WCF Service. When ever I do a call to the service, I want the Channel f开发者_如何学编程actory to trigger another event. Something like 'OnFunctionCall'. How can I add such a event handler to the ChannelFactory. I'm kinda rushed for time, so I hope someone could help.

Working with C#, .net 3.5 SP1

Kind Regards


One possible solution is to create an endpoint behavior and attach it to the factory endpoint (see below). That behavior would add an inspector to the channels the factory creates (which can be either an IClientMessageInspector or an IParameterInspector), and your inspector would trigger the OnFunctionCall event whenever a message is sent to the server.

var factory = new ChannelFactory<IService>(...);
factory.Endpoint.Behaviors.Add(new MyInspector());

For more information on message inspectors you can look at http://blogs.msdn.com/b/carlosfigueira/archive/2011/04/19/wcf-extensibility-message-inspectors.aspx, and for parameter inspectors you can look at http://blogs.msdn.com/b/carlosfigueira/archive/2011/04/26/wcf-extensibility-iparameterinspector.aspx.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号