Professional Documents
Culture Documents
Implementing Basic Hello World WCF Service
Implementing Basic Hello World WCF Service
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 features of Web Service, Remoting, MSMQ and COM+. WCF provides a common platform for all .NET communication.
Advantage
1. WCF is interoperable with other services when compared to .Net Remoting,where the client and service have to be .Net. 2. WCF services provide better reliability and security in compared to ASMX web services. 3. In WCF, there is no need to make much change in code for implementing the security model and changing the binding. Small changes in the configuration will make your requirements. 4. WCF has integrated logging mechanism, changing the configuration file settings will provide this functionality. In other technology developer has to write the code.
Disadvantage
Making right design for your requirement is little bit difficult.
Features
Hosting
Web Service
It can be hosted in IIS
WCF
It can be hosted in IIS, windows activation service, Self-hosting, Windows service [ServiceContraact] attribute has to be added to the class the method exposed to client
Programmin [WebService] attribute has to be g Model added to the class method exposed to client
[WebMethod] attribute represents the [OperationContract] attribute represents One-way, Request- Response are the One-Way, Request-Response, Duplex are
Operation
different operations supported in web different type of operations supported in service WCF is used for serialization XML 1.0, MTOM, Binary, Custom System.Xml.serialization name space System.Runtime.Serialization namespace is used for serialization XML 1.0, MTOM(Message Transmission Optimization Mechanism), DIME, Custom
XML
Encoding
Transports Protocols
Can be accessed through HTTP, TCP, Can be accessed through HTTP, TCP, Custom Security Named pipes, MSMQ,P2P, Custom Security, Reliable messaging, Transactions
WCF Fundamental
End Point Bindings and Behavior Contracts and Service host Message and Channel WCF client and Metadata
Implementing basic Hello World WCF Service To build a HelloWorld WCF Service by carrying out the following steps: Create the solution and project Create the WCF service contract interface Implement the WCF Service Host the WCF Service in the ASP.NET Development Server Create a client application to consume this WCF Service
Create a class Library HelloWorldService.cs using using using using using System; System.Collections.Generic; System.Linq; System.Text; MyWCFServices;
namespace HelloWorldService { public class HelloWorldService : IHelloWorldService { public string HelloWorld(string yourname) { return "Hello World : " + yourname; } } }
The HelloWorldService is a class library. It has to be hosted in an environment so that client applications may access it
<%@ServiceHost Service="MyWCFServices.HelloWorldService"%>
<serviceBehaviors> <behavior name="MyServiceTypeBehaviors"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> </behaviors> <services> <service name="MyWCFServices.HelloWorldService" behaviorConfiguration="MyServiceTypeBehaviors"> <endpoint address="" binding="wsHttpBinding" contract="MyWCFServices.IHelloWorldService"/> <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex"/> </service> </services> </system.serviceModel> </configuration>
namespace WcfClient { class Program { static void Main(string[] args) { Service s = new Service(); Console.WriteLine(s.HelloWorld("haiii")); Console.ReadLine(); } } }