.netWCF

WCF Service Implementing multiple contracts (part-4)

In this article, we will see how a single WCF service can Implement multiple service contracts and we will expose each service contract using different end point.

Let’s create a WCF service with multiple operation contract.

Steps:

    • Visual Studio –>File–>New–>Project–>Class Library –>Rename to EnterpriseService
    • Delete the default class class1.cs
    • Add a new Item to EnterpriseService
      • Rightclick on EnterpriseService–>Add–>New item–>WCF service–>Rename it to EnterpriseService.cs
      • Two cs files would be created EnterpriseService.cs and IEnterpriseService.cs
      • In IEnterpriseService.cs, You will see below code:
  •  Lets create multiple service and operation contract in IEnterpriseService.cs

  • Modify the code for EnterpriseService.cs to Implement multiple contracts.
  • How to make it available for the client to consume?

    Let’s add a console Project to the solution.
    Rightclick on solution–>add new project–>Console Application–>Rename it to CompanyServiceHost
    Add reference to EnterpriseService and System.ServiceModel
    Add Application configuration file and define the service endpoints,address,binding and contracts as given below.

    Add below code to Program.cs:

    Hit Ctrl+F5, and the service would be started.
    For testing this Service, Open another instance of visual studio

    • Visual Studio–>File–>New–>Project–>ASP.net web application–>Rename it to EnterpriseClient
    • Add service reference to it
    • Add System.ServiceModel reference to it
    • Add a web form and drag and drop 2 buttons and 2 labels. Name the button as GetEnterpriseInternetInformation and GetEnterpriseIntranetInformation

    • In Button click event, write Proxy classes like below
    • Save and hit Ctrl+F5 to run and test the Client and service

    You may like below articles also:
    Introduction to WCF
    Create WebService and Remoting Service
    WCF Service

    © 2015, www.techkatak.com. All rights reserved.

    2 thoughts on “WCF Service Implementing multiple contracts (part-4)

    Comments are closed.