The common way in WCF is to have a service with several operation contracts. Once an operation contract is defined you better not change it anymore because there are a lot of cases in which an operation change will break an existing client. But how about having just one general or universal operation contract (One single instead of many operation contracts. In fact I know you won’t be able to combine all in one but most of them). Here one example. That’s not the way I would finally realize it … just a simple illustration.
public enum Operation { Add, Sub, Mul, Div } [DataContract] public class Info { [DataMember] public Operation Operation { get; set; } [DataMember] public object Data { get; set; } } [ServiceContract] public interface IService { [OperationContract] Info Do(Info info); } public class Service : IService { public Info Do(Info info) { var result = -1; switch (info.Operation) { case Operation.Add: // cast info.Data and calculate result break; case Operation.Sub: // cast info.Data and calculate result break; } return new Info { Operation = info.Operation, Data = result }; } }
The main disadvantage on a universal contract is that you have to know how to pass data to the service and how to interpret the result. But this can be solved by documentation.
Currently I’m working on a project with a big client-server-application combined in one solution. It’s a big hassle to add one operation, update service references…
What speaks against to combine operation contracts? Do I have something more to consider?