Overloaded Methods as WCF OperationContracts

Interesting find today.  It is possible to create a WCF Service Contract that has overloaded methods on it.  The compiler doesn't complain at all. You can even attribute both as [OperationContract] and the compiler still won't complain.  If you go to use that Service Contract though, it will blow up and thrown an error about duplicate naming.  While this is frustrating you can get around it.  Options include, changing the name of one of the Operation Contracts or setting the name parameter on the Operation Contract attribute (i.e. [OperationContract(Name="SomeUniqueName")]).

Posted By: Donald Belcham

Published at

Comments

Rob Kitson
05/28/2008 05:42 PM by
Rob Kitson

Another thing that I found was cool is that the arguments that your methods accept can be polymorphic. You just have to declare what types it will accept, which can be done by hand (with an attribute for each sub-class) or by creating a static method that returns a list of all the types that inherit from a base class.