When I have started reading about WCF it looks like it involves lot XML configuration but its really cool.In this article I have started with simple example which does Hello world with WCF.
1) Create WCF Service Application
Create a Console application and reference it with System.ServiceModel. Add an interface/Contract through we expose the service functionalities. You could do this by attaching [ServiceContract] attribute for the interface.And add method that you want expose through the service contract, by attaching the attribute [OperationContract]. Now its time for the implementation of the method in your WCF service.
As shown below in the code snippet,
-
2) Configure your WCF Service.
Add configuration file to the solution to define the end points of your service.The endpoint of a service specifies an address where the service can be found, a binding that contains the information that a client must communicate with the service, and a contract that defines the functionality provided by the service to its clients.
Also define the service behavior and enable the service metadata behavior. End point is specified with the full length namespace of your contract which is WCFExample.WCFServer.ServerService.IWCFExample.
Now we specify the host base address in service tag. and it is http://localhost:8080/ServerService
The Configuration file will look as below,
-
3) running the WCF service
Instantiate the service in your Main as shown below.
-
4) Create a Client console application.
Add the service reference using the host address.it will create WCF client reference.Using the reference you could instantiate the WCF service and call the method, as shown below
Start WCF service and when you run the client application you could see the out put.