What is WCF (windows communication foundation) Service?
Windows Communication Foundation (Code named Indigo) is a programming platform and runtime system for building, configuring and deploying network-distributed services. It is the latest service oriented technology; Interoperability is the fundamental characteristics of WCF. It is unified programming model provided in .Net Framework 3.0. WCF is a combined feature of Web Service, Remoting, MSMQ and COM . WCF provides a common platform for all .NET communication.
contracts in WCF:
Service Contract Data Contract Message Contract Fault Contract
Creating simple application using WCF First open Visual Studio and click file --> Select New --> Website Under that select WCF Service and give name for WCF Service and click OK Now open IService.cs write the following code [ServiceContract] public interface IService { [OperationContract] string SampleMethod(string Name); }
|
|
After that open Service.cs class file and write the following code public class Service : IService { public string SampleMethod(string Name) { return "First WCF Sample Program " + Name; } }
|
Here we are using basicHttpBinding for that our web.config file system.serviceModel code should be like this and I hope no need to write any code because this code already exists in your web.config file insystem.serviceModel<system.serviceModel> <services> <service name="Service" behaviorConfiguration="ServiceBehavior"> <!-- Service Endpoints --> <endpoint address="" binding="wsHttpBinding" contract="IService"> <identity> <dns value="localhost"/> </identity> </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> </service> </services> <behaviors> <serviceBehaviors> <behavior name="ServiceBehavior"> <serviceMetadata httpGetEnabled="true"/> <serviceDebug includeExceptionDetailInFaults="false"/> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel>
|
|
Our WCF service ready to use with basicHttpBinding. Now we can call this WCF Service method console applications