Monday, July 13, 2009

Operation Overloading in WCF


This article will explain,

  1. What is Service Contract?
  2. How to achieve Operation overloading in Service.
  3. How to achieve operation overloading at client side.
  4. It explained the entire concept with supporting code as well.
  5. 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

    1. It is defined under namespace System.ServiceModel.
    2. It got 6 properties.
    3. 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
    1. Service is having 3 overloaded operations.
    2. Add operation is taking different parameters.
    3. Name properties are being used to achieve overload operation.
    4. 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.

See full detail:

No comments: