WCF – Overview ”; Previous Next WCF stands for Windows Communication Foundation. The elementary feature of WCF is interoperability. It is one of the latest technologies of Microsoft that is used to build service-oriented applications. Based on the concept of message-based communication, in which an HTTP request is represented uniformly, WCF makes it possible to have a unified API irrespective of diverse transport mechanisms. WCF was released for the first time in 2006 as a part of the .NET framework with Windows Vista, and then got updated several times. WCF 4.5 is the most recent version that is now widely used. A WCF application consists of three components − WCF service, WCF service host, and WCF service client. WCF platform is also known as the Service Model. Fundamental Concepts of WCF Message This is a communication unit that comprises of several parts apart from the body. Message instances are sent as well as received for all types of communication between the client and the service. Endpoint It defines the address where a message is to be sent or received. It also specifies the communication mechanism to describe how the messages will be sent along with defining the set of messages. A structure of an endpoint comprises of the following parts − Address Address specifies the exact location to receive the messages and is specified as a Uniform Resource Identifier (URI). It is expressed as scheme://domain[:port]/[path]. Take a look at the address mentioned below − net.tcp://localhost:9000/ServiceA Here, ”net.tcp” is the scheme for the TCP protocol. The domain is ”localhost” which can be the name of a machine or a web domain, and the path is ”ServiceA”. Binding It defines the way an endpoint communicates. It comprises of some binding elements that make the infrastructure for communication. For example, a binding states the protocols used for transport like TCP, HTTP, etc., the format of message encoding, and the protocols related to security as well as reliability. Contracts It is a collection of operations that specifies what functionality the endpoint exposes to the client. It generally consists of an interface name. Hosting Hosting from the viewpoint of WCF refers to the WCF service hosting which can be done through many available options like self-hosting, IIS hosting, and WAS hosting. Metadata This is a significant concept of WCF, as it facilitates easy interaction between a client application and a WCF service. Normally, metadata for a WCF service is generated automatically when enabled, and this is done by inspection of service and its endpoints. WCF Client A client application that gets created for exposing the service operations in the form of methods is known as a WCF client. This can be hosted by any application, even the one that does service hosting. Channel Channel is a medium through which a client communicates with a service. Different types of channels get stacked and are known as Channel Stacks. SOAP Although termed as ‘Simple Object Access Protocol’, SOAP is not a transport protocol; instead it is an XML document comprising of a header and body section. Advantages of WCF It is interoperable with respect to other services. This is in sharp contrast to .NET Remoting in which both the client and the service must have .Net. WCF services offer enhanced reliability as well as security in comparison to ASMX (Active Server Methods) web services. Implementing the security model and binding change in WCF do not require a major change in coding. Just a few configuration changes is required to meet the constraints. WCF has built-in logging mechanism whereas in other technologies, it is essential to do the requisite coding. WCF has integrated AJAX and support for JSON (JavaScript object notation). It offers scalability and support for up-coming web service standards. It has a default security mechanism which is extremely robust. Print Page Previous Next Advertisements ”;
Category: wcf
WCF – Useful Resources
WCF – Useful Resources ”; Previous Next The following resources contain additional information on WCF. Please use them to get more in-depth knowledge on this. WCF Online Training 24 Lectures 1.5 hours Tutorialspoint More Detail WCF Demystified: A Primary Course on WCF Services & Web API 10 Lectures 48 mins TELCOMA Global More Detail SignalR in Asp.Net – Advanced Course 106 Lectures 15.5 hours Corporate Bridge Consultancy Private Limited More Detail Print Page Previous Next Advertisements ”;
WCF – Security
WCF – Security ”; Previous Next A WCF service boasts of a robust security system with two security modes or levels so that only an intended client can access the services. The security threats that are common in a distributed transaction are moderated to a large extent by WCF. Key Security Features WCF service has four key security features as depicted in the figure below. Authentication − Here, authentication is not limited to identifying the sender of the message, but is mutual, i.e., authentication of the message receiver is required to rule out the possibility of any kind of middleman attack. Authorization − This is the next step taken by a WCF service to ensure security and it is here determined whether the service should authorize the caller to proceed further or not. Although authorization is not dependent on authentication, it normally follows authentication. Confidentiality − The exchange of information between a caller and a service is kept confidential to restrict its interpretation by others for whom the message is not intended. To make this possible, encryption is used along with a wide variety of other mechanisms. Integrity − The final key concept is maintaining integrity, i.e., offering the assurance that the message has not been tampered by anyone in its journey from the sender to the receiver. Transfer Security Mode WCF offers the following transfer security modes to ensure a secured communication between a client and a server. The diverse transfer security modes are mentioned below. None − This mode does not guarantee any kind of message security and the service does not get any credentials about the client. This mode is highly risky, as it may allow message tampering and hence not recommended. <wsHttpBinding> <binding name = “WCFSecurityExample”> <security mode = “None”/> </binding> </wsHttpBinding> Transport − This mode is the easiest way to achieve a secured transfer of message via the use of communication protocols such as TCP, IPC, Https, and MSMQ. This mode is more effective when the transfer is point-to-point and is used mostly in a controlled environment, i.e., intranet applications. <wsHttpBinding> <binding name = “WCFSecurityExample”> <security mode = “Transport”/> </binding> </wsHttpBinding> Message − The security mode allows mutual authentication and offers privacy to a great extent as the messages are encrypted and can be transported through http, which is not considered as a secure protocol. Here the security is provided end-to-end without considering how many intermediaries are involved in a message transfer and whether there is a secured transport or not. The mode is used typically by internet applications. <wsHttpBinding> <binding name = “WCFSecurityExample”> <security mode = “Message”/> </binding> </wsHttpBinding> Mixed − This security mode is not used frequently and client authentication is offered only at the client level. <wsHttpBinding> <binding name = “WCFSecurityExample”> <security mode = “TransportWithMessageCredential”/> </binding> </wsHttpBinding> Both − This security mode comprises of both transport security and message security to offer a robust security cover, but often results in overloading the overall performance. This one is supported by only MSMQ. <netMsmqBinding> <binding name = “WCFSecurityExample”> <security mode = “Both”/> </binding> </netMsmqBinding> All WCF bindings except BasicHttpBinding have some extent of transfer security by default. Message Security Level Message level security is not dependent on WCF protocols. It is employed with message data itself by encrypting the data by using a standard algorithm. A number of client credentials are available for different bindings for the message security level and these are discussed below. Client credentials for message level security in WCF None − Here, encryption is used to secure the message, whereas no client authentication is performed which means that the service can be accessed by an anonymous client. Except for BasicHttpBinding, all WCF bindings support this client credential. However it should be noted that for NetNamedPipeBinding, this client credential is not available at all. Windows − Here, both message encryption and client authentication take place for a real-time logged-in user. In this case too, unlike all other WCF bindings, NetNamedPipeBinding is not available and BasicHttpBinding does not lend its support. UserName − Here, messages are encrypted as well as secured by offering a UserName, and clients are authenticated as they need to offer a password. BasicHttpBinding just like the above two client credentials, does not support UserName and it is not available for NetNamedPipeBinding. Certificate − Along with message encryption, both the client and the service get an authentication with certificate. This client credential is available and is supported by all WCF bindings except NetNamedPipeBinding. IssuedToken − Issued Tokens from an authority like Cardspace are used to authenticate the messages. Encryption of messages are also performed here. The following code shows how client credentials are configured in the WCF message security level/mode. <netTcpBinding> <binding name = “WCFMessageSecurityExample”> <security mode = “Message”> <message clientCredentialType = “None”/> </security> </binding> </netTcpBinding> <netMsmqBinding>…</netMsmqBinding> </bindings> <behaviors>…</behaviors> Here, it must be noted that the transport security mode has an edge over the message security level, as the former is faster. It does not require any additional coding and offers interoperability support, and thus does not reduce the overall performance. However, from security point of view, the message security mode is more robust and is independent of protocols and offers end-to end security. Print Page Previous Next Advertisements ”;
WCF – Exception Handling
WCF – Exception Handling ”; Previous Next A WCF service developer may encounter some unforeseen errors which require reporting to the client in a suitable manner. Such errors, known as exceptions, are normally handled by using try/catch blocks, but again, this is very technology specific. Since a client”s concern area is not about how an error occurred or the factors contributing to an error, SOAP Fault contract is used to communicate the error message from the service to the client in WCF. A Fault contract enables the client to have a documented view of the errors occurred in a service. The following example gives a better understanding. Step 1 − An easy calculator service is created with divide operation which will generate general exceptions. using System; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Runtime.Serialization; usingSystem.ServiceModel; usingSystem.Text; namespace Calculator { // NOTE: You can use the “Rename” command on the “Refactor” menu to change // the interface name “IService1” in both code and config file together. [ServiceContract] public interface IService1 { [OperationContract] int divide(int num1, int num2); // TODO: Add your service operations here } } The coding for the class file is show below − Now, when we try to divide the number 10 by zero, the calculator service will throw an exception. The exception can be handled by try/catch block. Now, when we try to divide any integer number by 0, it will return the value 10 because we have handled it in the catch block. Step 2 − FaultException is used in this step to communicate the exception information to the client from the service. public int Divide(int num1, int num2) { //Do something throw new FaultException(“Error while dividing number”); } Step 3 − It is also possible to create a custom type to send the error message using FaultContract. The steps essential to create a custom type are mentioned below − A type is defined by the use of data contract and the fields intended to get returned are specified. The service operation is decorated by the FaultContract attribute. The type name is also specified. A service instance is created to raise exceptions and custom exception properties are assigned. Print Page Previous Next Advertisements ”;
WCF – Developers Tools
WCF – Developers Tools ”; Previous Next For developing a WCF service application, there are mainly two tools – Microsoft Visual Studio and CodePlex. Microsoft Visual Studio is a complete package of development tools, necessary for developing a large number of diverse applications like ASP.NET web applications, desktop applications, mobile applications, and many more. Microsoft Visual Studio uses the .NET framework functionality. CodePlex on the other hand is an open-source project hosting site of Microsoft that offers several free tools for WCF service application development. Microsoft Visual Studio There are many editions of Microsoft Visual Studio and initially it (Visual Studio 2005) was not an ardent supporter of WCF development. At present, Visual Studio 2008 is the only Microsoft IDE available for the development of WCF service applications. Nowadays, the latest version of Microsoft Visual Studio 2010 is also a preferred tool for developing WCF service application. There is also a readymade template in Visual Studio for developing WCF service application. Selection of such a template leads to addition of files for the following purposes − Service contract Service implementation Service configuration Requisite attributes get added automatically and a simple “Hello World” service gets created by Microsoft Visual Studio without even writing any code. CodePlex CodePlex was launched by Microsoft in June 2006 and since then, it has been used by a large number of developers across the world to create .NET projects successfully. Some of the tools offered by CodePlex for developing WCF service applications are as follows − wscf.blue − This is a Microsoft Visual Studio add-in, and also “contract-first” development toolset that facilitates the defining of the WCF service operations, and generating a code skeleton accordingly. An important link for the same is − https://wscfblue.codeplex.com WCFProxyGenerator − This is also a Microsoft Visual Studio add-in. The tool is used to extend the client-side generation and offer additional error handling. For having more information regarding this particular development tool, visit https://wcfproxygenerator.codeplex.com WCFMock − Testing of WCF service can be a complicating task and this development tool offers a convenient solution for the unit testing of WCF services by its useful classes. For more information regarding this tool, visit https://wcfmock.codeplex.com Another free tool for the development of WCF service applications in an easy manner is WCFStorm. Its LITE version offers many striking features for dynamically invoking and testing WCF services, editing the service binding, modifying WCF URL endpoint, etc. Print Page Previous Next Advertisements ”;
WCF – Home
WCF Tutorial PDF Version Quick Guide Resources Job Search Discussion WCF stands for Windows Communication Foundation. It is a framework for building, configuring, and deploying network-distributed services. Earlier known as Indigo, it enables hosting services in any type of operating system process. This tutorial explains the fundamentals of WCF and is conveniently divided into various sections. Every section of this tutorial has adequate number of examples to explain different concepts of WCF. Audience The objective of this tutorial is to help those readers who want to learn the basics of WCF from scratch. After completing this tutorial, the readers will acquire sufficient knowledge on WCF and advance to a higher level of expertise. Prerequisites Anyone having a basic understanding of the .NET framework can use this tutorial to learn WCF. Prior awareness of web services will help pick up the concepts faster. Print Page Previous Next Advertisements ”;
WCF – Versus Web Service
WCF – Versus Web Service ”; Previous Next There are some major differences that exist between WCF and a Web service which are listed below. Attributes − WCF service is defined by ServiceContract and OperationContract attributes, whereas a web service is defined by WebService and WebMethod attributes. Protocols − WCF supports a range of protocols, i.e., HTTP, Named Pipes, TCP, and MSMQ, whereas a web service only supports HTTP protocol. Hosting Mechanisms − Various activation mechanisms are there for WCF hosting, i.e., IIS (Internet Information Service), WAS (Windows Activation Service), Self-hosting and Windows Service, but a web service is hosted only by IIS. Services − WCF supports a robust security, trustworthy messaging, transaction and interoperability, while a web service only supports security services. Serializer − WCF Supports DataContract serializer by employing System.Runtime.Serialization, whereas a web service supports XML serializer by making use of System.Xml.Serialization. Tools − ServiceMetadata tool (svcutil.exe) is used for client generation for a WCF service, while WSDL.EXE tool is used for generating the same for a web service. Exception Handling − In WCF, unhandled exceptions are handled in a better way by making use of FaultContract. They do not return to the client like in a web service as SOAP faults. Hash Table − It is possible to serialize a Hash Table in WCF, but this is not the case in a web service. Bindings − WCF supports several types of bindings like BasicHttpBinding, WSDualHttpBinding, WSHttpBinding, etc., while a web service supports only SOAP or XML. Multithreading − WCF supports multithreading by using the ServiceBehavior Class, whereas this is not supported in a web service. Duplex Service Operations − WCF supports duplex service operations apart from supporting one-way and request-response service operations, whereas a web service does not support duplex service operations. Print Page Previous Next Advertisements ”;
WCF – Architecture
WCF – Architecture ”; Previous Next WCF has a layered architecture that offers ample support for developing various distributed applications. The architecture is explained below in detail. Contracts The contracts layer is just next to the application layer and contains information similar to that of a real-world contract that specifies the operation of a service and the kind of accessible information it will make. Contracts are basically of four types discussed below in brief − Service contract − This contract provides information to the client as well as to the outer world about the offerings of the endpoint, and the protocols to be used in the communication process. Data contract − The data exchanged by a service is defined by a data contract. Both the client and the service has to be in agreement with the data contract. Message contract − A data contract is controlled by a message contract. It primarily does the customization of the type formatting of the SOAP message parameters. Here, it should be mentioned that WCF employs SOAP format for the purpose of communication. SOAP stands for Simple Object Access Protocol. Policy and Binding − There are certain pre-conditions for communication with a service, and such conditions are defined by policy and binding contract. A client needs to follow this contract. Service Runtime The service runtime layer is just below the contracts layer. It specifies the various service behaviors that occur during runtime. There are many types of behaviors that can undergo configuration and come under the service runtime. Throttling Behavior − Manages the number of messages processed. Error Behavior − Defines the result of any internal service error occurrence. Metadata Behavior − Specifies the availability of metadata to the outside world. Instance Behavior − Defines the number of instances that needs to be created to make them available for the client. Transaction Behavior − Enables a change in transaction state in case of any failure. Dispatch Behavior − Controls the way by which a message gets processed by the infrastructure of WCF. Concurrency Behavior − Controls the functions that run parallel during a client-server communication. Parameter Filtering − Features the process of validation of parameters to a method before it gets invoked. Messaging This layer, composed of several channels, mainly deals with the message content to be communicated between two endpoints. A set of channels form a channel stack and the two major types of channels that comprise the channel stack are the following ones − Transport Channels − These channels are present at the bottom of a stack and are accountable for sending and receiving messages using transport protocols like HTTP, TCP, Peer-to-Peer, Named Pipes, and MSMQ. Protocol Channels − Present at the top of a stack, these channels also known as layered channels, implement wire-level protocols by modifying messages. Activation and Hosting The last layer of WCF architecture is the place where services are actually hosted or can be executed for easy access by the client. This is done by various mechanisms discussed below in brief. IIS − IIS stands for Internet Information Service. It offers a myriad of advantages using the HTTP protocol by a service. Here, it is not required to have the host code for activating the service code; instead, the service code gets activated automatically. Windows Activation Service − This is popularly known as WAS and comes with IIS 7.0. Both HTTP and non-HTTP based communication is possible here by using TCP or Namedpipe protocols. Self-hosting − This is a mechanism by which a WCF service gets self-hosted as a console application. This mechanism offers amazing flexibility in terms of choosing the desired protocols and setting own addressing scheme. Windows Service − Hosting a WCF service with this mechanism is advantageous, as the services then remain activated and accessible to the client due to no runtime activation. Print Page Previous Next Advertisements ”;