Before reading this article, I highly recommend reading the previous parts:
Let's make two OperationContract with same name in ImyService.
- using System.ServiceModel;
-
- namespace myFirstApp
- {
- public interface IMyService
- {
- [OperationContract]
- int AddTwoNo(int intFirstNo, int intSecondNo);
-
- [OperationContract]
- double AddTwoNo(double dbFirst, double dbSecond);
- }
- }
And implement these two OperationContracts in MyService.svc.cs:
- using System.ServiceModel;
-
- namespace myFirstApp
- {
- [ServiceBehavior(AddressFilterMode=AddressFilterMode.Any)]
- public class MyService : IMyServiceNew
- {
- public int AddTwoNo(int intFirstNo, int intSecondNo)
- {
- return intFirstNo + intSecondNo;
- }
-
- public double AddTwoNo(double dbFirst, double dbSecond)
- {
- return dbFirst + dbSecond;
- }
- }
- }
I got an error while updating my service reference.
Error says: cannot have two operations in the same contract with the same name. You can change the name of an operation by changing the method name or using the name property of OperationContractAttribute.
By default WSDL does not support operational overloading, but we can do this using the Name property of OperationContract.
- using System.ServiceModel;
-
- namespace myFirstApp
- {
- [ServiceContract(Name="IMyService")]
- public interface IMyServiceNew
- {
- [OperationContract(Name="AddTwoNoInteger")]
- int AddTwoNo(int intFirstNo, int intSecondNo);
-
- [OperationContract(Name = "AddTwoNoDouble")]
- double AddTwoNo(double dbFirst, double dbSecond);
- }
- }
Now update your service reference and run the application. It will work fine.
I hope this article is helpful for you.
Thanks :)