Many developers would answer this question as Yes because C# is used in WCF and C# is Object oriented, so a natural thinking would be WCF should also support method overloading.
The fact is it does not, surprised right :-). If you have a method which is overloaded you need to use the "Name" parameter in the "OperationContract" to ensure that the proxy class generates different names.
See the below code for more details. In the below code we have "GetData" which is overloaded but we are saying to the client to generate the methods with name "GetData" and "GetData1".
[ServiceContract]
public interface IService1
{
[OperationContract(Name="GetData")]
string GetData(int value);
[OperationContract(Name="GetData1")]
string GetData(int value, int value1);
// TODO: Add your service operations here
}
Do also see the below video why practically we can not do method overloading in WCF service: -
Asked In: Many Interviews |
Alert Moderator