I want to implement function overloading in WCF but i am not allowed to do so
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json)]
branch_view[] GetBranches();
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json)]
branch_view[] GetBranches(int pageNo , int pageSize);
The error i got is:
Cannot have two operations in the same contract with the same name, methods GetBranches and GetBranches in type QHRService.IEntityService violate this rule. You can change the name of one of the operations by changing the method name or by using the Name property of OperationContractAttribute.
Why WCF does not allow Function overloading.
I can change the name to get my function work but any reasons?
Any help is appreciated
WCF is designed to be a completely generic communications framework – which means that clients might not be .NET-based, and therefore might not have any understanding of method overloading.
There is functionality available for having methods with the same name, but it’s a pain to get working reliably; I would strongly recommend just biting the bullet and having different method names, even though it feels ‘wrong’.