HI WELCOME TO SIRIS
Showing posts with label wcf tutorials. Show all posts
Showing posts with label wcf tutorials. Show all posts

A Brief Version History of WCF

WCF stands for Windows Communication Foundation. It is Microsoft's latest technology that enables applications in a distributed environment to communicate with each other. WCF is Microsoft's unified programming model for building service-oriented applications. It enables developers to build secure, reliable, transacted solutions that integrate across platforms and interoperate with existing.
WCF Version History
WCF Version
Introduced with .NET & IDE
Features Detail
4.5
4.5 and Visual Studio 2012
  1. Task-based Async Support
  2. Contract-First Development
  3. WCF Configuration Validation
  4. Web Socket Support
  5. UDP Endpoint Support
  6. New Https protocol mapping on IIS
  7. Streaming Improvements
  8. Multiple Auth support for single endpoint
4.0
4.0 and Visual Studio 2010
  1. Simple Configuration
  2. Serialization Enhancements
  3. Support for WS-Discovery
  4. Routing Service
  5. Standard Endpoints
  6. Workflow Service
3.5
3.5 and Visual Studio 2008
  1. UriTemplates Support
  2. Support for REST Style Services
  3. Asp.NET Ajax Integration and JSON support
  4. Added WS* Specification Support
  5. Support for RSS and Atom feeds
3.0
3.0 and Visual Studio 2005
  1. Introduced first version of WCF with many features like Address, Binding, Contract, Sessions, Instancing, and Concurrency management
What do you think?
I hope you will enjoy the WCF features. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.

Introduction to WCF

WCF stands for Windows Communication Foundation. It is Microsoft's latest technology that enables applications in a distributed environment to communicate with each other. WCF is Microsoft's unified programming model for building service-oriented applications. It enables developers to build secure, reliable, transacted solutions that integrate across platforms and interoperate with existing.
WCF is an umbrella technology that covers ASMX web services, .NET Remoting, WSE, Enterprise Service, and System.Messaging. It is designed to offer a manageable approach to distributed computing, broad interoperability, and direct support for service orientation. WCF supports many styles of distributed application development by providing a layered architecture.

ABC of Windows Communication Foundation

What are the ABCs of WCF? "ABC" stands for address, binding, and contract.
  1. Address (Where)

    It specifies the location of the service means, where the service is hosted. The service hosting URL may be like http://server/wcfService. Clients will use this location to communicate with your service.
  2. Binding (How)

    It specifies how the client will communicate to the service. We have different protocols (like http,tcp,named pipe,msmq) for the WCF to communicate to the client.
  3. Contract (What)

    It specifies what the service will do. For this purpose, we have a different contract like as Data Contract, Operation Contract, Message Contract, Fault Contract. I will discuss all these later.

WCF Hosting

A WCF service is a component that can be called by other applications. It must be hosted in an environment in order to be discovered and used by others. The WCF host is an application that controls the lifetime of the service. With .NET 3.0 and beyond, there are several ways to host the service.
  1. Self hosting

    A WCF service can be self-hosted, which means that the service runs as a standalone application and controls its own lifetime. This is the most flexible and easiest way of hosting a WCF service, but its availability and features are limited.
  2. Windows services hosting

    A WCF service can also be hosted as a Windows service. A Windows service is a process managed by the operating system and it is automatically started when Windows is started (if it is configured to do so). However, it lacks some critical features (such as versioning) for WCF services.
  3. IIS hosting

    A better way of hosting a WCF service is to use IIS. This is the traditional way of hosting a web service. IIS, by nature, has many useful features, such as process recycling, idle shutdown, process health monitoring, message-based activation, high availability, easy manageability, versioning, and deployment scenarios. All of these features are required for enterprise-level WCF services.
  4. Windows Activation Services hosting

    The IIS hosting method, however, comes with several limitations in the service-orientation world; the dependency on HTTP is the main culprit. With IIS hosting, many of WCF's flexible options can't be utilized. This is the reason why Microsoft specifically developed a new method, called Windows Activation Services, to host WCF services.
    Windows Process Activation Service (WAS) is the new process activation mechanism for Windows Server 2008 that is also available on Windows Vista. WAS hosting is possible only with IIS 7.0. Additional WCF components also plug into WAS to provide message-based activation over the other protocols that WCF supports, such as TCP, MSMQ, and named pipes. This allows applications that use the non-HTTP communication protocols to use the IIS features such as process recycling, rapid fail protection, and the common configuration systems that were only available to HTTP-based applications.

Introduction to Web Service

Web services are components on a Web server that a client application can call by making HTTP requests across the Web. ASP.NET enables you to create custom Web services or to use built-in application services, and to call these services from any client application. Basically web service is any piece of software that makes itself available over the Internet and uses a standardized XML messaging system.XML is used to encode all communications to a Web service.
In simple sense, Web Services are means for interacting with objects over the Internet. The Web serivce consumers are able to invoke method calls on remote objects by using SOAP and HTTP over the Web. WebService is language independent and Web Services communicate by using standard web protocols and data formats, such as :
  1. Http
  2. Xml
  3. Soap

Example

  1. Weather Reporting

    You can use Weather Reporting web service to display weather information in your personal website.
  2. Stock Quote

    You can display latest update of Share market with Stock Quote on your web site
  3. News Headline

    You can display latest news update by using News Headline Web Service in your website.

Web Service Properties

  1. First, a Web service can have a public interface, defined in a common XML grammar. The interface describes all the methods available to clients and specifies the signature for each method. Currently, interface definition is accomplished via the Web Service Description Language (WSDL).
  2. Second, if you create a Web service, there should be some relatively simple mechanism for you to publish this fact. Likewise, there should be some simple mechanism for interested parties to locate the service and locate its public interface. The most prominent directory of Web services is currently available via UDDI, or Universal Description, Discovery, and Integration.

Web Service Advantages

  1. Since Web services are platform & language independent, hence any web services from different sources can communicate to one another.
  2. Web Service messages are formatted as XML and this message is sent via HTTP, so that they can reach to any machine on the internet without being blocked by firewall.

Difference between WCF and ASP.NET Web Service

Leave a Comment
.NET provides various options for creating services under .NET Framework. Before WCF, ASP.NET Web Services are used to ceate service in .NET Framework. Now WCF is the latest programming model for building and developing service-oriented application. WCF allows applications to communicate with each other in distributed environment. WCF is a set of technologies that covers ASMX web services, Web Services Enhancements (WSE), .NET Remoting and MSMQ. In this article, you will learn the differences between ASP.NET Web Service and WCF.
Difference between WCF and ASP.NET Web Service
WCF
ASP.NET Web Service
ServiceContract and OperationContract attributes are used for defining WCF service.
WebService and WebMethod attributes are used for defining web service.
Supports various protocols like HTTP, HTTPS, TCP, Named Pipes and MSMQ.
Supports only HTTP, HTTPS protocols.
Hosted in IIS, WAS (Windows Activation Service), Self-hosting, Windows Service.
Hosted only in IIS.
Supports security, reliable messaging, transaction and AJAX and REST supports.
Support security but is less secure as compared to WCF.
Supports DataContract serializer by using System.Runtime.Serialization.
Supports XML serializer by using System.Xml.Serialization.
Supports One-Way, Request-Response and Duplex service operations.
Supports One-Way and Request-Response service operations.
WCF are faster than Web Services.
Web Services are slower than WCF
Hash Table can be serialized.
Hash Table cannot be serialized. It can serializes only those collections which implement IEnumerable and ICollection.
Unhandled Exceptions does not return to the client as SOAP faults. WCF supports better exception handling by using FaultContract.
Unhandled Exceptions returns to the client as SOAP faults.
Supports XML, MTOM, Binary message encoding.
Supports XML and MTOM (Message Transmission Optimization Mechanism) message encoding.
Supports multi-threading by using ServiceBehaviour class.
Doesn’t support multi-threading.
What do you think?
I hope you will enjoy the both ASP.NET Web Service and WCF. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.


Difference between WCF Proxy and Channel Factory

Leave a Comment
There are two ways : Proxy and Channel Factory; to create a WCF Client or calling a WCF Service. In this article, I am going to expose the difference between Proxy and Channel Factory.
  1. WCF Proxy

    A WCF proxy is a CLR class that exposes the service contract. A Service proxy class has the service contract operations and some additional operations for managing the proxy life cycle and the connection to the service.
    There are two ways to create a WCF proxy as given below:
    1. Using Visual Studio by adding service reference to the client application.
    2. Using SvcUtil.exe command-line utility.
  2. Channel Factory

    A channel factory creates channels of different types that are used by client to send messages to the service. ChannelFactory class is used with a known interface to create the channel. This approach is commonly used when you have access control to both the server and the client.
    1. WSHttpBinding binding = new WSHttpBinding();
    2. EndpointAddress endpoint = new EndpointAddress("http://localhost/WcfService/MyService.svc/ws");
    3.  
    4. ChannelFactory<IMyService>channelFactory = new ChannelFactory<IMyService>(binding,endpoint );
    5. IMyService channel = channelFactory.CreateChannel();
    6.  
    7. //calling service operation
    8. channel.DoWork();
    9.  
    10. //Close channel
    11. channelFactory.Close();

Difference between WCF Proxy and Channel Factory

Proxy
Channel Factory
Only requires the service URL to access the service.
Requires direct access to the assembly which contains the service contract i.e. must have information about service interface.
Simple and easy to understand
Not easy since channels are complex and network-related
Proxy is best when your service is used by several applications.
Channel Factory is best when your service is tightly bound to a single application
Proxy can be created by using Visual Studio or SVCUtil tool.
ChannelFactory class is used to create channel and for accessing the service.
What do you think?
I hope you will enjoy the tips while programming with WCF. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.


Understanding Session Management in WCF

Leave a Comment
WCF manage session by creating the instance of the service class. These created instance(s) handle the incoming service request. In WCF, session is the way of managing the services instance(s) so that server can used these instances in an optimized way. At server side InstanceContext class is used to manage service class instance.
In WCF, there are three Instance Management way as given below:
  1. Per Call

    In this way, each request is served by a new service instance. It means a new service instance is created for each request and destroyed after the request is served.
    This make your WCF service stateless means you can’t maintain states between WCF calls.
  2. Per Session

    In this way, each and every client requests are served by a new single service instance. It means a new service instance is created for a client all requests and destroyed after the client finished its activity.
    This way make your WCF service state-full means you can maintain states between WCF calls.
  3. Single

    In this way, all clients’ requests are served by a single service instance. It means a single service instance is created to handle all the clients’ requests and never destroyed after serving the request.
    This makes your WCF service data shared globally.

How WCF Session is different from Asp.Net Session?

WCF Session management is different from Asp.Net Session Management in the following ways:
  1. WCF Sessions are created and terminated by service client.
  2. Server use session to manage service instances, not to store some general data like Asp.Net.
  3. WCF Session does not mainly rely on Session ID like Asp.Net, a particular field with in the header or body of a group of messages can also be considered as a part of session.
  4. There may be different Session ID at client and server side unlike Asp.Net.
What do you think?
I hope you will enjoy the tips while programming with WCF. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.


Understanding Message Exchange Patterns (MEP) in WCF

Leave a Comment
Message Exchange Patterns describes the way of communication between Client and Server means how client and server would be exchange messages to each other. There are three types of message exchange patterns
  1. Request-Reply

    In this communication, client sends the message to the service and waits for reply from the service. Within a ReceiveTimeout period (default timeout is one minute), if the service doesn't respond to the client then the client will receive a TimeoutException. In this pattern, client waits for the reply mes-sage, even if the service operation's return type is void.
    This the by default message exchange pattern in WCF. All WCF bindings except MSMQ-based bindings supports this pattern.
    1. [ServiceContract]
    2. public interface RequestReplyService
    3. {
    4. [OperationContract]
    5. string GetData(int value);
    6.  
    7. [OperationContract(IsOneWay = false)]
    8. void SaveData(string value);
    9. }
    To define this pattern, you can set IsOneWay property to false explicitly, but by default it is false. So there is need to define ISOneWay property for Request-Reply pattern. A Request-Reply operation returns header with an HTTP status code of 200 (OK) and a full SOAP response in the message body.
  2. One-Way

    In this communication, client sends the message to the service and doesn't wait for reply from the service. In this pattern, receiver doesn’t send any response to the sender, even if any error occurs in the communication.
    This pattern doesn’t supports output parameters, by-reference parameters and return value to an operation, otherwise you will receive an InvalidOperationException.
    All of the WCF bindings support one-way operations.
    1. [ServiceContract]
    2. public interface OneWayService
    3. {
    4. [OperationContract(IsOneWay = true)]
    5. void SaveData(string value);
    6. }
    A One-Way operation returns only header with an HTTP status code of 202 (Accepted) without message body. This pattern is commonly used with per-call or singleton services only.
  3. Duplex

    In this communication, client and services can sends messages to each other by using One-way or request-reply messaging.
    Only bidirectional-capable bindings support this pattern like as WS Dual, TCP and IPC bindings.
    To make a duplex contract, you must also define a callback contract and assign the typeof that callback con-tract to the CallbackContract property of your service contract’s ServiceContract attribute as shown in be-low example.
    1. [ServiceContract(CallbackContract = typeof(DuplexServiceCallback))]
    2. public interface DuplexService
    3. {
    4. [OperationContract(IsOneWay = true)] //One-Way
    5. void SaveData();
    6.  
    7. [OperationContract] //Request-Reply.
    8. string GetData();
    9. }
    10.  
    11. public interface DuplexServiceCallback
    12. {
    13. [OperationContract(IsOneWay = true)]
    14. void Progress(string status);
    15. }
    For this pattern, you must also specified the binding as wsDualHttpBinding with in your web.config as shown below-
    1. <services>
    2. <service name="WCFServiceApp.DuplexService">
    3. <endpoint address ="" binding="wsDualHttpBinding" con-tract="WCFServiceApp.IDuplexService">
    4. </endpoint>
    5. </service>
    6. </services>
    What do you think?
    I hope you will enjoy the tips while programming with WCF. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.