Operation Overloading in WCF
Objective:
This article will explain,
- What is Service Contract?
- How to achieve Operation overloading in Service.
- How to achieve operation overloading at client side.
- It explained the entire concept with supporting code as well.
- This will explain in detail of all the aspect of method overloading and manually configuration at client side.
What is Service Contract?
ServiceContractAttribute class is defined as
- It is defined under namespace System.ServiceModel.
- It got 6 properties.
- It could be applied either on service contract interface or service contract class.
Could we achieve Operation overloading in Service Contract?
How to achieve operation overloading?
By using Name property of OperationContractAttribute class.
OperationContractAttribute class
Code Sample
- Service is having 3 overloaded operations.
- Add operation is taking different parameters.
- Name properties are being used to achieve overload operation.
- We will give aliased name to achieve overload using Name properties of OperationContractAttribute class.
Service Contract (IAddCalculator.cs)
Service Implementation (AddCalculator.cs)
When the client imports the contract and generates the proxy, the imported operations will have the aliased name.
At client side, the below methods will be imported.
Comments