IntroductionThis article demonstrates how to create a WCF service application. This article also covers basic information of all the contracts and a code demonstration.What is WCF?WCF is a combined feature of Web Service, Remoting, MSMQ and COM+. WCF provides a common platform for all .NET communication. It is a part of .Net 3.0. Difference between WCF and Web service
Let's see how to create a WCF service application step-by-step.Step 1Start Menu >> All Programs >> Microsoft Visual Studio 2010 >> Microsoft Visual Studio 2010In that "File" >> "New" >> "Project..."Step 2
Step 3Now your Windows Communication Foundation service application is ready as a default service. You will see in Solution Explorer Service1.svc and IService1.csOpen the IService1.cs file, as in:In this file you willl find a ServiceContract, OperationContract and DataContract.Service ContractService contract is an attribute applied to an interface i.e. IService1. It describes which operations the client can perform on the services. Operation ContractOperation Contract is an attribute applied to methods in interfaces i.e. IService1. It is used to define a method in an interface.Data ContractDataContract defines which data types are passed to and from the service. It is used to define a class and the DataMember attribute is used to define the properties.WCF Contracts map directly to a corresponding web services standard:
Step 4There is one method "GetData" which accepts parameters of type int.An implementation of this method is in the Service1.svc.cs file. This method returns a string with the value you passed as a parameter.Step 5Now let us run this service. You can test your service in WCF Test Client. WCF Test Client is a GUI tool which enables us to enter parameters, invoke services with these parameters and view the responses returned by services.Now double-click on the "GetData" method and enter a parameter value of type System.int32. Here I enter "25" as a parameter value and press the "Invoke" button. You will get "You entered: 25" as a response.ConclusionWe have seen a very basic example of a WCF Service application. We entered a parameter value of type int and got the entered value as a response.
Microsoft Certified ProfessionalMCTS - Framework 4MCTS - Windows Communication Foundation MCTS - Data AccessMCPD - Framework 4MCT - Since 2013MS - Html5 & CSS3MCSD - Web Application
C# Corner. All contents are copyright of their authors.