WCF

Introduction to Windows Communication Foundation
Overview:
The Windows Communication Foundation 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 features of Web Service, Remoting, MSMQ and COM+. WCF provides a common platform for all .NET communication. All these features in  one umbrella called WCF service.


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. I will try to help you on solving these difficulties in the following article.
Difference between Web service and WCF service:   
Web service is a part of WCF. WCF offers much more flexibility and portability to develop a service when comparing to web service. Still we are having more advantages over Web service, following table provides detailed difference between them.
Features
Web Service
WCF
Hosting
It can be hosted in IIS
It can be hosted in IIS, windows activation service, Self-hosting, Windows service
Programming
[WebService] attribute has to be added to the class
[ServiceContraact] attribute has to be added to the class
Model
[WebMethod] attribute represents the method exposed to client
[OperationContract] attribute represents the method exposed to client
Operation
One-way, Request- Response are the different operations supported in web service
One-Way, Request-Response, Duplex are different type of operations supported in WCF
XML
System.Xml.serialization name space is used for serialization
System.Runtime.Serialization namespace is used for serialization
Encoding
XML 1.0, MTOM(Message Transmission Optimization Mechanism), DIME, Custom
XML 1.0, MTOM, Binary, Custom
Transports
Can be accessed through HTTP, TCP, Custom
Can be accessed through HTTP, TCP, Named pipes, MSMQ,P2P, Custom
Protocols
Security
Security, Reliable messaging, Transactions

Microsoft Visual Studio 2008

Microsoft Visual studio 2008 provides new features for WCF compared to Visual Studio 2005. These are the new features added to VS 2008.

1.    Multi-targeting

1. We can create application in different framework like Framework 2.0, 3.0 and 3.5


 2 .    I am going to create small WCF application called WCFServiceSample

                                      

3 .    Adding new item called Message.svc WCF service file as below screenshot.

4.    Create method called SendMessage in IMessage Interface as shown in the below code.

namespace WcfServiceSample
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IMessage" in both code and config file together.
    [ServiceContract]
    public interface IMessage
    {
        [OperationContract]
        string  SendMessage();
    }
}


5 .    Implementing IMessage in Message Class as shown in the below code.

namespace WcfServiceSample
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Message" in code, svc and config file together.
    public class Message : IMessage
    {
      
        public string SendMessage()
        {
            return "Hello Wcf Sample";
        }
    }
}

6.     Build the WcfServicesample application.

7.    Add new web project called “WcfServiceSampleClient” .
8.    Add WCF service Reference to “WcfServiceSampleClient” as shown below screen shot.

9.  Accessing WCF service reference in Default.aspx page as shown in the below code.

namespace WcfServiceSampleClient
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            MessageService.MessageClient messageServiceClient = new MessageService.MessageClient();
           lblMessage.Text=messageServiceClient.SendMessage();
           lblMessage.BackColor = System.Drawing.Color.Yellow;
        }
    }
}

10. We should be able to see the label text in web site as shown below screen shot.






No comments:

Post a Comment