Im creating a service contract in my wcf application and it contains a lot of methods.
I find it very annoying to write an OperationContract
attribute to all of them.
Is there any simple way how to say "every method in my ServiceContract
interface is an OperationContract
" ?
thank you
Yes, you can use AOP framework for that. E.g. with PostSharp:
This attribute used to mark methods which should not be operation contracts:
Now all you need to do is apply
AutoServiceContract
attribute to service interface. That will addServiceContract
attribute to interface, and all public methods will be marked withOperationContact
attribute (except those which haveNotOperationContract
attribute):Spring.Net has built-in feature
ServiceExporter
and all you need is such config:For more details check documentation and this forum thread. You need to have service definition in
app.config
called same as the Spring object:MyService
Next step will be to decorate all objects with
DataContract
attribute. Any ideas? Not very good one is to useXmlSerializerFormat
attribute on service contracts (can be added by Spring too).No, you need to do it on each and every method. it defines an operation that is part of a service contract in a Service. There is a possibility that some of the methods are not intended for Exposing.