Windows Communication Foundation (WCF), which is a unified programming model for building service-oriented applications. It enables developers to build secure, reliable, transacted solutions that integrate across platforms and interoperate with existing investments.
- Start a new class library project under your solution.
-
Define the service contract
We are defining the service contract. The service contract specifies what operations the service supports. An operation can be thought of as a Web service method. You create service contracts by defining a C# or Visual Basic interface. An interface has the following characteristics:
- The interface should import System.ServiceModel class.
- Each method in the interface corresponds to a specific service operation.
- For each interface, you must apply the ServiceContractAttribute attribute.
- For each operation/method, you must apply the OperationContractAttribute attribute.
- The next step for creating a WCF application is to add code to implement the WCF service interface that you created in the previous step.
- Start another Console application project under your solution. This will be acting as the host for your service.
- Your application source code files will look like below,
- Write a Client console application to consume the service.
- Start host application and generate the proxy and config files from the metadata exchange end point using “svcutil”.
Program.cs : ServiceHost
App.config : This config file hosts the service in the mentioned service URL. You can mention the machine name and designated port to uniquely host your service.
Program.cs : ServiceClient