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 classCode 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.The client can use the generated proxy at it is. Sample code is given below.OutputFew problems in above approachSo, up to here, we have achieved Operation Overloading. But there is one problem here that client side is importing alias name rather than the same name for all overloaded operation. By below code , we could see that client proxy is importing alias name.Solution of above problem Click on Object browser at client side. Click on ServiceReference1. Click on AddCalculatorClient at object browser. Double click to open the code browser. In AddCalculatorClient partial class, modify the imported operation contracts. Just modify the code as, And modify the interface at client side asSave and compile the code.Now at the client side, we could see that Add method is overloaded with 3 different parameters. So, now we could modify the client code as, OutputConclusion:This article explained, 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.
Just modify the code as, And modify the interface at client side asSave and compile the code.Now at the client side, we could see that Add method is overloaded with 3 different parameters. So, now we could modify the client code as, OutputConclusion:This article explained,
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: