tags:

views:

716

answers:

2

What is best practice for creating wrapper for WCF service call? I think it is necessary to monitor all calls in the same place, I am thinking to use this kind of code, is this right idea?

RetType t = ServiceExecutionContext<IServiceChanel>.Execute(s=>s.GetServiceMethod());


What kind of wrapper are you use in your enterprise applications?
Thanks a lot!

+4  A: 

WCF has a model that allows you to be in the service call chain. I would use that rather than trying to wrap every service call if all that you are trying to do is some logging (which WCF is already very good at doing if you turn diagnostics on in the config file) and common things like that around your service calls.

Here is a good MSDN article about how to create custom behaviors for WCF services.

Brian ONeil
A: 

If you need to, write your own Message Inspector.

WCF also has message logging builtin. By default, you can log easily to a file using the System.Diagnostics.XmlWriterTraceListener, however if you need to write the log elsewhere (say, a database), you could write your own trace listener.

I would recommend this approach over a message inspector... message inspectors are too easy to write incorrectly and hurt performance without knowing what you are doing.

Anderson Imes