Author Archives: IMRAN ABDUL GHANI

About IMRAN ABDUL GHANI

Imran Abdul Ghani is working as Software Developer(Senior) with extensive knowledge in Web development technologies especially C#, ASP.NET, MVC, WCF, Web API, ADO.NET Entity Framework, jQuery etc. He has several years of experience in designing/developing enterprise level applications. He is Microsoft Certified Solution Developer for .NET (MCSD.NET) since 2005. You can reach his blogging at www.webdevelopmenthelp.net, www.topwcftutorials.net, and www.sharepointfordummies.net.

What Everyone Ought to Know about Big Data & Hadoop

Data is a critical aspect of every business or organization. In fact, it is capable of influencing an organization’s plan of action and can also be utilized for the success and growth of a project. This article is an introduction to Big Data & Hadoop and includes all the basics that you need to know.

What is Big Data?

Big Data and Hadoop 2Big Data is basically a term used to describe a large volume of complex, diverse and fast-changing data which is acquired from new data sources as well as the analysis of it. The complexity and diversity of these data sets makes it extremely difficult to store and manage it efficiently with traditional data processing and management tools. Big Data is classified into two main types, namely structured data and unstructured data. SQL databases are examples of structured data while document files as well as data from search engine results are examples of unstructured data or data whose form is unknown. As organizations strive to make their mark in a highly competitive market, there is need for more effective ways to manage data which involves handling huge amounts of data which is no mean task. It is therefore important to incorporate Big Data development strategies that are capable of transforming your business.

You can follow here for Best Online Data Science Courses and MOOCs.

Characteristics of Big Data

Followings are the key characteristics of Big Data:

1. Volume

The term Big Data describes data which is enormous in size. The value of data largely depends upon its size. Volume is a major characteristic that determines whether data is big or not.

2. Variety

This refers to the heterogeneous nature of data whether structured or unstructured. In the past, most applications considered databases and spreadsheets as the only sources of data, but today, data is available in many forms such as photos, emails, videos, audio, PDFs, monitoring devices among others. However, this variety also poses a few challenges that include storage, mining as well as analysis.

3. Velocity

This term generally refers to how fast data is generated or the speed of data generation and processing to meet the demands which also determines the potential in that data. The velocity of Big Data involves the speed at which data from sources such as business processes, mobile devices, social media sites, application logs and sensors flows in. This flow of data is not only massive in nature but is also continuous.

4. Variability

This is the inconsistency which data can show at times, thus affecting the effective management and handling of data.

Importance of Big Data Development

A business or organization’s ability to process and develop Big Data comes with several benefits that include:

  • Improved customer service
  • Early identification of business risks if any
  • Ability of a business to utilize outside intelligence in decision making
  • Better operational efficiency

Companies can access data from search engines and other social sources of data such as Facebook and Twitter to fine tune their business strategies. Customer feedback has also been improved thanks to new systems that have adopted Big Data technologies. These technologies can greatly improve the efficiency of a business.

Risk Associated with Big Data

Some of the biggest risks of big data include:

  • Lack of privacy
  • Cyber security threats
  • Over relying on data which can be risky sometimes
More interesting Big Data & Hadoop related:

Big Data and Hadoop – Features and Ecosystem

Hadoop is simply a framework that uses a simple programming model to allow for the distributed processing of huge chunks of data sets across several commodity computers. This framework can effectively store and analyze data available in different machines quickly and in a cost effective way. Hadoop uses the MapReduce concept that allows it to divide a query into small portions before processing them in parallel. Some key features of Hadoop include:

  • Flexibility in data processing
  • Scalability (new nodes can be added onto the platform on need basis)
  • Fault tolerance (Availability of data backup)
  • Extremely fast data processing
  • A robust ecosystem
  • Cost effective (Reduces the cost of storage)

The Hadoop ecosystem comes with great projects such as Hive, MapReduce, Apache Pig, HBase, HCatalog, Zookeeper among many other new tools that are designed for better data processing.

Hadoop Architecture and Building Blocks

Big Data and HadoopHadoop is composed of four main building blocks, namely Hadoop CommonHadoop Distributed File system, MapReduce and Yet Another Resource Negotiator (YARN). The Hadoop Distributed File System provides reliable data access and storage across the various nodes of a Hadoop cluster while the Hadoop Common supports other Hadoop modules. Yarn assigns storage, memory and CPU to all applications running on the Hadoop cluster. YARN is Hadoop’s core architectural center that enables multiple data processing engines like reel-time streaming and interactive SQL to handle data that is stored in a single platform.

Big Data Analytics

Many organizations are using Big Data analytics while making operational and strategic decisions. By examining Big Data sets, an organization can discover hidden patterns, customer preferences, market trends, unknown correlations and any other useful information that can help in designing more effective marketing campaigns as well as improved customer service.

This is an overview of Big Data and related concepts/technologies. More related articles with tons of information will be shared later.

Understanding OData in simplest way

In computing technology, OData(Open Data Protocol) is a web protocol used to query and update data. OData is based on REST protocol and is helpful in simple and standard view of the data on web even by simplest of the browsers. It is considered best for building and consumption of the RESTful APIs. It is built upon an exetension of Atom Publishing Protocol – AtomPub. OData has provisions to fulfill any custom needs of RESTful APIs for extensions.

In simple words, goal of OData is to make available an efficient and wide access to data; no matter how it is stored. OData Services

This protocol is used for making data services that are based upon HTTP. By using HTTP commands, it makes the requesting and updating of resources easy. This also provides the whole query language straight into the URL as:OData Services

For Example, querying all students with Age greater than 12 as follows:

http://services.school.com/OData/DataService.svc/Students?$filter=age gt 12

OData Query Operator Represents Query
Numeric Comparison
Gt Greater Than /Students?$filter=age gt 8
Ge Greater Than Or Equal /Students?$filter=age ge 8
Lt Less Than /Students?$filter=age lt 12
Le Less Than Or Equal /Students?$filter=age le 12
Logical Comparison
And Logical And /Students?$filter=age le 12 and age gt 8
Or Logical Or /Students?$filter=age le 8 or age gt 12
Not Logical Not /Students?$filter=not endsWith(StudentName, ‘Ahmad’)
Arithmetic Comparison
Add Addition /Students?$filter=marks add 10 lt 30
Sub Subtraction /Students?$filter=marks sub 5 gt 90
Mul Multiplication /Students?$filter=marks mul 2 lt 10
Div Division /Students?$filter=marks div 2 gt 80

The above table is just given for the purpose of basic understanding, but a complete list of OData Query Operators can be found here.

OData Data Model

Entity data model , EDM, that’s the name of abstract data model used by OData services. It does not make it necessity to use a particular data model or implementation. The only important thing that is to be kept in mind, is that the HTTP interface exposed by the service should be consistent with the protocol used by OData.

Entity Container can have multiple Entity Set and each Entity Set can have multiple Entities where an Entity represents a record in a table. An Entity can have Properties (column) and Navigation Properties(used as an association with other Entities.

OData Data Model

The main theme behind OData protocol is to provide REST based protocol to Create, Read, Update and Delete style operations. The specifications of OData define the standardization of typed, CRUD interface for manipulation of data. This is achieved by providing the collection of entries. This facilitates the ease of getting, updating and removing of data entries. You can find a complete practical example of RESTful Service for all CRUD Operations with source code.

This way we see that open data protocol is an application, basically based on Atom and JSON. This is mainly for the CRUD and Typed operations to standardize the queries in a way so that the large number of users can interact with the services well.

Exam: 70-487- Developing Microsoft Azure and Web Services

Microsoft Certification Exam: 70-487 validates one’s knowledge for Developing Windows Azure and Web Services. It’s one of the three exams in Web Application Track of MCSD (Microsoft Certified Solution Developer) Certification as stated in below diagram. MCSD Certification Exam is designed to test one’s skills for high level, real world programming. Technical Certification from Microsoft is recognized widely by almost all industries and organisation. This exam is taken in form of various sets that adds step by step improvements to proficiency of trainees.

Are you looking for MCSD Exam: 70-487 Questions with Correct Answers and Short Description?

Purpose here is to provide an extensive aggregated post by WCF Tutorial for all available reference material on Exam: 70-487 over the Web.Exam: 70-487 Certification

I have categorized this post into three major parts as follows:

  • Good Reference Material available online including related Tutorials, eBooks and articles on Windows Azure, WCF Services, Microsoft Entity Framework, Web API-based Services etc.
  • Free Online Tests
  • Complete Online Preparation Exam: 70-487
  • At the end, I have added few sample questions that gives you an idea about the Real Certification Exam Questions. You can also get a link to a pool of Questions with correct answer and description for FREE.

I followed the same pattern in another post about Exam: 70-486 (Developing ASP.NET MVC Web Applications) at www.webdevelopmenthelp.net.

Let’s start with the list of key skills being tested during this Exam as stated by Microsoft:

  • Accessing Data
  • Querying and Manipulating Data by Using the Entity Framework
  • Designing and Implementing WCF Services
  • Creating and Consuming Web API-based services
  • Deploying Web Applications and Services

Microsoft’s website also states that from 30th April, 2014 onward, this exam includes contents related to:

  • Visual Studio 2013
  • Windows Azure Updates

In order to get latest details about each skill area and updates, please visit Exam: 70-487 web page.

Exam: 70-487 – Reference Material

Exam Ref: 70-487 by Microsoft Press

As for most of the Microsoft Exams, you can find Microsoft Press book available in both Paper and PDF. Same for this book written by William Ryan, Wouter de Kort and Shane Milton target to fulfill specific requirements of Exam: 70-487. In my opinion, it’s the best and most relevant reference guide for this exam also. Anyone wants to improve his/her skills on Developing Windows Azure and Web Services; also planning to take exam should have a copy of this book (either hard or eBook).Exam Reference 70-487

Courseware by Firebrand

This Courseware by Firebrand is a good reference material covering all Exam modules according to required skills Set as mentioned above. Extensive details explained through slides for each topic including Entity Framework, ASP.NET Web API, Windows Azure, Azure Storage, Azure Service Bus, Hosting, Deploying and Scaling Services. It also includes details about Designing and Extending Windows Communication Foundation Services, Security in WCF, LINQ and latest features in Visual Studio 2013.

Most importantly, all the concepts are explained with the help of proper example. You will find a lot of code samples in this courseware.

Data Storage Offerings on Azure Platform

Microsoft TechNet contains huge information about important topics of exam such as comparison between windows server and azure data storage and various offerings of azure platforms. This link will also help you to know details about Blob and its types.

Microsoft Azure

Here is another workable resource for you that contain information about services of this platform including Cache details, Redis cache, In-Role cache and shared cache. Complete content is managed in easy to understand form with best collection of information.

WCF Service Example by WCF Tutorial

WCF Tutorial provides a lots of practical example for beginners as well as professional developers to grasp the concepts very easily. Starting with FAQs series to practically implementing WCF Services, RESTful Services, Concurrency, Security, MEP (Message Exchange Patterns) and Transactions are available.

WCF Fundamentals by PluralSight

Here you can learn techniques of building advanced connected systems on the platform of Microsoft with the help of Windows Communication Foundation or simply called as WCF. Contents of this WCF Service Tutorial include introductory part, programming services, programming clients and RESTful Services.

Windows Azure Training

This is an effective resource for basic knowledge of Windows Azure and is highly useful for all IT professionals. This platform incorporates operating system, methods of data storage and applications based on cloud.

Entity Framework Development Videos

This video tutorial will help you to know basics of framework development and is enough capable to build strong knowledge of all aspects related to this topic.

ASP.NET Web API

This course provides complete knowledge of ASP.NET Web API that is a powerful as well as flexible framework for designing HTTP dependent clients and endpoints. Various sections of this valuable resource include introduction part, uniform interface, HttpClient, Hosting, Security and Extensibility. You will be able to get deep knowledge of facts through this resource.

Practical Guide to ASP.NET Web API

A complete and practical guide for ASP.NET Web API provides comprehensive material for developing HTTP Services. Starting from a very basic Web API in 3 simple steps to performing all CRUD Operations, Model validation and it’s limitations and Web API OData etc. It’s available in both Web Edition and PDF Download.

Exam: 70-487 – Online Tests | Questions and Answers PDFs

WCF Free Online Test

WCF Tutorial has created Online Test specifically for WCF (Windows Communication Foundation) and constantly updating this test with fresh questions.

Microsoft 70-487 Tests

Here you will be able to get unlimited access to instantly downloadable questions and answers in form of premium files. These files are helpful to improve your knowledge and provide best practice material for MCSD exam 70-487. It includes some sets of brain dumps, test kits, exam collections and pass guide for MCSD exam.

Exam: 70-487 – Complete Practice Exams

Before you take any of the actual MCSD Exam, it’s always better and highly recommended to take some Online Practice Exam. Because practice exam will not cost you much but it will provide you a good idea of your preparation at any stage. But I recommend to prepare well first and when you are 100% confident to take exam, please take a practice exam to validate your skill. A practice exam will give you a good idea about your preparation, then decide to go for Actual Certification Exam.

70-487 Exam Sample Questions with Answers

Below are few sample Questions with Correct answers to give you an idea about the Exam.


Question 1: The SSDL (Storage schema definition language) is a XML syntax that represents the storage model of the underlying database which holds the information about the data store and it is incorporated into the .edmx file.
The above statement is a correct one?

  • True
  • False

Answer: True
Description: SSDL is a XML syntax which represents Storage model


Question 2: You have a table with one column and Unique constraint set. You have set EnforceConstraints to True and populated the DataSet with the table. What would happen if you are creating new rows with identical values?

  • A. System Error
  • B. It accepts new values
  • C. Compiler error
  • D. Throws ConstraintException

Answer: D
Description: If EnforceConstraints is set to true, it triggers ConstraintException if violated.


Question 3: You have the object which already exists in the database and you need to make aware the Entity Framework regarding this object. Which method you would use?

  • A. ObjectContext.AddObject()
  • B. ObjectContext.Attach()

Answer: B
Description: ObjectContext.Attach() is used when the existing object is modified.


For More Exam: 70-487 FREE Questions with Correct Answer and Short Description, Follow here. [Free Membership Required]

This is all I have for now but I’ll keep updating this with more relevant study material. I’ll appreciate if you could contribute to this post by adding more material on Exam: 70-487 through comments.

Handling Transaction in WCF

How would you feel, when you ordered something, you gotta money-debited text peeping out from your mobile but couldn’t see a order successful page while shopping at your favorite portal? Don’t you yell at the portal which didn’t send you the product and the bank which took your bucks for no reason! So what causes this frustration?WCF - Handling Transactions

It might be because of whole lot of reason, it might be because of sudden power outage, hardware crash, network jam or it could be because of natural disaster as well. The reasons can be many but if the transaction was handled in the way it should be, the guy who ordered wouldn’t be frustrated and hatred on making a online transaction further. As a computer professionals we should definitely know about Online transactions and its management. More specifically WCF transaction and its Propagation & Protocols.

What is meant by Transaction?

Transaction can be explained as, a set of one or more atomic units operations that are executed all as a whole. To be more practical, lets take the example stated above and consider that you are anxiously awaiting for your order-successful page but you only get the debited message from bank. It means that either of operations failed, here the failure is on e-commerce portal side. The two actions here are considered as one and it should be executed as a whole, if either one failed the transaction should be aborted, otherwise there involved a loss of material & time. Hence we come to know that transaction plays a vital role in Online commerce.Transactions in WCF

ACID characteristics of Transaction

Transaction can be classified clearly with its ACID properties. The abbreviation states, four different properties namely:

Atomicity : This property explains the same as stated above i.e. Either of operation should be executed successfully else if one failed the whole set of operation should be aborted and changes made till now should be reverted back.

Consistency : The transaction should deliver a consistent outcome as expected in both cases. For instance if the ordered product’s cost is $50 and your bank balance is $750. The outcome expected should be either $700 or $750 in respective to success and failure of transaction.

Isolated : Isolating the transaction i.e making it confidential till we have a successful transaction. So that partial comittments are kept private from clients.

Durable : The transaction should sustain even in midst of external failures. Hence it can be relied on further. Handling in all gateways makes a transaction durable.

Transactions in WCF

A WCF service, where a Service is created and it will be consumed by one or more Clients. The transaction happens at two points here i.e. Service level and Client level. The basic transaction properties are been handled by the Microsoft Framework, in-order to get essence out of it, we should handle the Transaction explicitly in WCF.

In-order to enable the transaction in WCF, there involves a Configuration with the application.

Here the Service can manipulate the logic and sends to the Client or else it can be like Client validates and manipulate the data and propagates the result to the Service. So a developer should understand about the Transaction Propagation involved.

Also the default binding in WCF i.e. BasicHttpBinding wont explicitly supports Transaction, so to get the things work we need to make use of the below bindings available in WCF.

  • NetTcpBinding
  • NetNamedPipeBinding
  • WSHttpBinding
  • WSDualHttpBinding
  • WSFederationHttpBinding

Note : By default the transaction is disabled. You can follow here to understand about choosing the most appropriate binding for a WCF Service in various scenarios.

Glimpse on enabling Transaction

Transaction in WCF was introduced in version 2.0. It can included into the project with namespace System.Transactions. It was supported by many platforms such as SQLServer, MSMQ, ADO.NET etc. The three prominent attributes involved in enabling Transactions are:

  • ServiceBehaviour Attribute
  • OperationBehaviour Attribute
  • TransactionFlow Attribute

To know more about enabling transaction in WCF, please check out another WCF Tutorial “5 Simple Steps to Enable Transactions in WCF”.
Once you are comfortable with Enabling Transaction in WCF, let us dive into 2PC protocol where the Transaction process is based on.

Two phase committed protocol (2PC)

The Two Phase Committed protocol, also abbreviated as 2PC is a set of constraints involved in controlling and handling Transaction process. This protocol tries to avoid failure and recover from it. 2PC can be broadly classified into two main phases such as Voting phase and Completion phase.Two Phase Committed Protocol in WCF
Voting Phase :
As we saw earlier that, transaction basically involves Server side and Client side where the service and consumption happens. Here the protocol accommodate those with Co-ordinator (Server) a master system and Cohorts (Clients) which are in one or more numbers. The voting system works in way to ensure there is no failure. Co-ordinator shoots out a message to all the Cohorts and asks for Commit. Co-ordinator set to commit only if the Cohorts votes as Yes, it doesn’t set to commit if it votes No or Failure to reply.

Completion Phase :
The Co-ordinator sends Commit message to all the Cohorts connected. The Co-ordinator commits only if it gets the acknowledgment from the Cohorts. If it receives No or times-out then it sends out a Rollback message to all the Cohorts where the Cohorts revert with the help of Log file which it maintains from during the Initial phase.

Transaction Propagation

WCF propagation or act of spreading the transaction across the service boundary enables both Client and Service to participate in each other’s action. i.e Triggers a service to participate in a client’s transaction and in the same way it paves a path to include operations on multiple services in the same transaction.

Configuration for enabling transaction propagation

The WCF checks for this configuration while processing transaction and act accordingly based on the setup. Let us discuss about the basic configuration involved.

  • First and foremost step involved in enabling the Transaction propagation is to trigger on the TransactionFlow in the bindings for relevant transaction support protocol. Open Web.Config file and add the following XML snippet, which states transactionFlow to True.Enable Binding for Transaction Flow
  • If youarestatingOperationBehaviour in your project,WCF provides us two transaction related properties such as:
    • TransactionAutoComplete : If this property is used, the transaction will be auto-completed if there happens no exceptions.
    • TransactionScopeRequired : This property specifies the requirement of transaction for the decorated method.WCF OperationBehavior Attribute
  • Once the bindings and behaviors are handled the next important step is to decorate Service Operations with TransactionFlow Attribute. They are three in types such as:
    • TransactionFlowOption.Allowed – This attribute allows the client transaction to be happen seamlessly.
    • TransactionFlowOption.Mandatory – As the name suggest, the client and Service must use the transaction based on the binding it is configured.
    • TransactionFlowOption.NotAllowed – This attribute if used will not allow the client the to propagate its own transactions.TransactionFlow in WCF

Benefits of WCF Transaction Propagation

  • Job processing and handling are processed when the resources are not so busy.
  • Idle time of Computer resources are minimized.
  • Since the resources are less overheaded, it saves money & time.
  • Provides resource sharing among many users.

Hope this WCF tutorial gives you a detail touch up about WCF transaction, protocol and propagation. Kindly let us know if you have any questions.
Happy WCF learning!

Top 10 Interview Questions and Answers Series:

Hosting WCF Service in WAS Simplified

Windows Communication Foundation Service also known as WCF Service provides us an optimal way in creating Services. It can be hosted in a variety of ways (as explained by below diagram) including IIS, Console Application, .NET application or can be hosted as Windows Service. So why should we go for WAS hosting i.e. Windows Activation Service. In this WCF Tutorial, we are going to learn that what is WAS?, how to host in it and the benefits of using it.WCF Hosting Options

.NET introduced WCF technology from the version 3.0 and it provides a huge stack of protocol supports such as HTTP, TCP, MSMQ, IPC, and WCF REST based etc. Initially while Microsoft introduced IIS 6.0 the WCF service hosting in IIS only supported HTTP protocol. Later WCF shipped with Windows Vista where it supported all other protocols such as TCP, MSMQ, and Named Pipes etc. This enables a convenient way of implementing WCF service without much programming.

Note: The WCF service hosted completely in WAS, works similarly like legacy Web Service (ASMX).

Create a simple WCF Service

  • We are really going to build a very simple WCF service, I will use Visual studio 2010 & IIS 7.5 throughout the lesson. Open Visual Studio -> New project -> WCF -> Select WCF Application Service.WCF Service Application
  • Once the application is open, you can see WCF example methods auto generated. We can just make use of it. It’s quite simple.WCF Example
  • Run the WCF application or hit F5, now you can see WCF Test Client pops out, asking for the input values. You can make sure your application is working correctly.WCF Test Client
  • Now let us try initiating in browser via HTTP protocol. We need to modify the Web.config file accordingly.Web.Config in WCF Service
  • Locate the URL pointing to the .svc file that we created now.WCF Service Running
  • Cool, we got our service live, kindly note: All these are been handled by IIS server where it instantly host our service application to the random port. By default as we discussed it only supports HTTP protocol. Further, you can follow here if interested to create and work with HTTP Services.

Now let us try mapping our application to a Non-HTTP protocol, modify the bindings of Web.Config as below.Non-Http Protocol

Run the WCF application or hit F5. As expected our IIS doesn’t understand the protocol and says that it “Could not find a base address….”WCF Tutorial - Base Address

We can resolve this by setting up Windows Activiation Service (WAS) and this is the main objective for this WCF Tutorial.

Install and Set up WAS

  • Add a Virtual directory and map our application from IIS directly so that we can play around with Protocol bindings.WCF Web Service
  • To install WAS, go to Control Panel -> Program & Features – > Turn On & Off Windows feature -> Microsoft .NET Framework 3.5.1 -> Check on the Windows Communication Foundation Non-HTTP Activation. This is the WAS which is OFF in default.WCF Non-Http Activation
  • Once, we turn on the Non-HTTP activation, go to the IIS -> Our Hosted Service -> Advanced Settings -> Add the net.tcp protocols under Enabled Protocols.
    Note: We can as many protocols as Comma Separated Values.WCF Advanced Settings
  • Next, we have to set the binding value to net.tcp protocol, to do that go to IIS -> Our Hosted Service -> Site Bindings -> Add -> Type as net.tcp and Binding information as “<Port Number>:*”.WCF Site Bindings
  • Finally, try navigating our browser to the same URL as we tried before.WCF Hosting in WAS

That’s it, we just hosted our WCF Service application in a Windows Activation Service type. Play around with it. You can consume the service by mapping the endpoint in your application as usual. Now let us see the benefits of hosting our application in WAS.

Benefits of Hosting in WAS

Hosting in WAS (Windows Activation Service) has many advantages like Multiple Protocol Support, Reliability etc. Lets discuss briefly few of the most important ones.

  • Low Overhead: Being a windows component it is completely separate from IIS server host and relieved from Overhead associated with hosting server.
  • Supports multiple protocols: As with IIS (Internet Information Services) by default HTTP is supported only and thus we enabled it by switching on WAS and triggered required protocols.
  • Health monitoring: Hosting in WAS provides us enough flexibility in monitoring the health of each application service.
  • Memory leak avoidance: WAS Recycling feature helps us to control the memory leaks and thus improves the efficiency.
  • Configurations: The configuration can entirely controlled via config files such as web.config or app.config. For instance the directory listing setting true enables user to access the folder and files.

Thus WCF service hosting in WAS environment has more benefits and improves the stability of the service. Clients can rely on the service more than any other hosting technique. You must have learnt something new from this WCF Service Hosting Tutorial. Waiting for your feedback and comments.

Download Complete Source Code for this WCF Article here.

Happy WCF Programming!

Other WCF Services and Related Tutorials:

Step by Step approach to create a WCF Data Service

When comes to Service Oriented Architecture or Programming, Microsoft’s WCF (Windows Communication Foundation) technology plays a prominent role in the field. It enables developers to segregate Services/Data with Client, hence it helps in developing a loosely coupled application with ease.

Before digging into further definition of what is WCF Data Service is, let me clarify the common confusion between WCF Service and WCF Data Service. In WCF Service, the focus is on creating Operations, where the generic services are implemented. It works with various protocols/techniques such as SOAP, MSMQ, HTTP, TCP etc. Whereas WCF Data Service is completely focused on creating Data as a service. If we have a data model and if we need to make it available for the clients to consume it, then WCF Data Service is the right way. It only supports REST based HTTP protocol.

Here in this WCF tutorial, we are going to follow a simple step by step approach to create and consume a WCF Data Service. You can also download complete source code here.

WCF Data Services 4.5 exposed

Microsoft’s .NET framework provides us a reliable Service technology called WCF Data Service, where it enables us to create a Data service which expose our data-model to the clients. Here the services, which it creates are based on OData i.e. Open Data Protocol, it is a standard technique to create and consume REST (Representational State Transfer) APIs, where the services are accessed by URLs via normal HTTP requests.WCF Data Services

HTTP request includes GET, POST, PUT and DELETE verbs through which a CRUD based service can be created. This Data service can be consumed by any client application that supports HTTP-OData and format of receiving data can be of XML, JSON or Raw text.

WCF Data Services Tutorial – A Step by Step Approach

Create a WCF Data Service

You need Visual Studio 2010 IDE & SQL Server in your machine as prerequisites for building WCF Data Service. It would be nice if you have the basic .NET knowledge. Let’s get started!

    • Open Visual studio 2010 and create a Web -> ASP.NET Web Application with a language of your choice, either C# or VB. I’ve used C# throughout the lesson. The reason why we are creating an ASP.NET Web application is because in order to host and consume the WCF Data Service we need a hosting and client application.WCF Tutorial - Step 1
    • Once the application is created, we need a DataModel where it is going to be served. So let’s create a SQL Server database. Right click on the App_Data -> Create SQL Server database and define the schema as below.

WCF Tutorial - Step 2

  • Now let’s feed some values into our newly created database table.WCF Data Services - Step 3
  • We have our Database and Table ready, now it’s time for us to create an Entity Data Model. Right click on the project and Add New item -> Select ADO.NET Entity Data Model, a Wizard pops up, proceed further with it. Below screenshots helps you building a Model.ADO.NET Entity Data ModelModel ContentsADO.NET Data ConnectionChoose Database Objects
  • Now we are done with Entity Model and for our Schema structure, this how the Model looksEntity Data Model
  • We are good with our basic implementation in-order to adopt a WCF Data Service into our application. Ready to go. Let’s create a WCF Data Service. Right click on the Project -> Add New Item -> Select WCF Data Service.WCF Tutorial - Data Service
  • WCF creates us a basic template code for us to start with.WCF Tutorial Template Code
  • Before moving forward, let us keep our Database Entity name handy. It can be found in Web.Config under Connection String.Database Connection String
  • Here we have replaced the template code with EntityName and Set of rules which decides the rights of access.DB Entities WCF Tutorial
  • If you run the application or just hit F5 selecting the WCF Data Service file. It opens up a browser and navigates us to http://localhost:/WCFDataFilename.svc . You can see a XML document with title holds to the Entity Name we created.WCF Data Services File
  • To get the full database values as a XML model, just postfix the Entity Name with URL. As below.WCF Service XML Model
  • Quite simple right! We do have some syntax approach in accessing the resource via OData. Example if we need a Single record, access it like belowOData - WCF Tutorial

If you are interested in getting more information about data visualization, you can follow here for online tableau training.

Consume Data Model via WCF Data Service

  • Open Default.aspx page of the ASP.NET Web application that we created a moment ago. Create a Grid View.ASP.NET Web Application
  • In-order to consume the WCF Data Service, we need to add a Service Reference. Right click on Reference Folder -> Add Service Reference -> Click on the Go. Since our Data service resides inside our application it fetches URL automatically.Add Service Reference
  • Create an instance for the referenced Service, place the URI of our running Data Service. Map the Entity with the DataSource of the GridView.Running Data Services
  • Just run the application or hit F5 to see the Magic!WCF Data Service
  • Great! We have successfully created a WCF Data Service and Consumed it. If you are interested to understand more about Web API service, follow Web API tutorial.

Retrieve the data in JSON Format

JSON format is quite easier to read programmatically and faster than XML. In-order to get the data in JSON format, we need to have special class file “JSONPSupportBehaviour.cs”. Include the file into our project and just decorate the Data Service class with the attribute JSONSupportBehaviourAttribute.

That’s it, now we can just retrieve the data in JSON format, by following OData special URL format i.e post fixing with $format=json.

You can get the JSONPSupportBehaviour.cs by downloading the Source code.JSONP Support Behavior

WCF Tutorial

WCF Tutorial

Hope this article would have sown little knowledge on WCF Data Service. Kindly let us know if you have any questions.

Download Source Code for this WCF Tutorial

Enjoy WCF Programming with WCF Tutorial!

Top 10 Interview Questions and Answers Series:

Top 5 WCF Tutorials in Year 2014

I wanted to say Happy New Year to all readers and wishing that 2015 be an amazing year for you and your family. Whatever WCF Tutorial has achieved so far was not possible without you. So, many thanks for your feedback and contribution here.

Year 2014 was the best year for WCF Tutorial so far. This year, WCF Tutorial presented it’s readers around 30 very helpful tutorials on various topics related to Windows Communication Foundation. Alongwith these articles, WCF Tutorial introduced an Online WCF Free Test for readers to simply test their knowledge on Windows Communication Foundation.

Above mentioned articles covering the following WCF topics:

  • WCF RESTful Services
    Complete Practical Guide to RESTful Services
  • WCF 4.5 features
    A complete 7 article series of new features in WCF 4.5 explaining each feature in details with code sample.
  • Message Exchange Patterns in WCF
  • Security in WCF (including Transport Level Security and Message Level Security)
  • Contracts in WCF including Service, Operations, Data and Fault Contracts
  • WCF Bindings Configuration and Proxy Generation
  • Hosting a WCF Service (IIS, Windows Service, Console Application)
  • Difference between different versions of Windows Communication Foundation including WCF 3.5, 4.0 and 4.5.

Here in this post, I wanted to put together top 5 articles of Year 2014 with respect to readership and user feedback.

  1. Practical Guide to WCF RESTful Services
  2. Transport Level Security Vs Message Level Security in WCF
  3. What’s New in WCF 4.5
  4. 3 Simple Ways to generate proxy in WCF
  5. Difference between DataContract and MessageContract in WCF

1. Practical Guide to WCF RESTful Services

This WCF Tutorial is undoubtedly the most read and downloaded (PDF copy is available) article of year 2014. Actually, it’s a group of 7 chapters/articles that gives you practical understanding about RESTful services in WCF.
RESTful Services also known as HTTP Services utilizes full features of HTTP as opposite to SOAP based WCF Service where it’s used as simply a transport. We only think about methods in a system while working with SOAP-based WCF Services. On the other hand, when working with REST-based services, we think in terms of resources and resource’s representations. RESTful or HTTP services gives us many advantages including better performance, more efficient, interopable and scalable systems etc.

WCF RESTful ServiceThis WCF RESTful Service tutorial provides helpful material starting from a very basic WCF RESTful Service, performing all CRUD Operation, Consuming Services using jQuery, working with JSON data, Automatic format selection and finally explaining Exception handling in a RESTful Service is provided. If you are a beginner and wanted to grasp WCF RESTful services step by step, this Tutorial is the right way to proceed.

2. Transport Level Security Vs Message Level Security in WCF

Support for various security concepts are built-in Windows Communication Foundation and we have discussed these concepts in another tutorial. Here in this tutorial, we discussed the difference between handling security at two different levels i.e. Transport level security and Message level security.Message Level Security Vs Transport Level Security

Further elaborating the recommended scenarios for both security options. And finally explaining the difference with respect to advanatages and disadvantages in using both approaches.

3. What’s New in WCF 4.5

Microsoft released WCF 4.5 with a bunch of new exciting features. I have summarized all these new features in one post and further linked to multiple detailed tutorials with code sample and screenshots wherever required.New Features in WCF 4.5

List of Features covered in this WCF Tutorial includes:

  • Task-based Asynchronous Programming Model
  • Configuration validation in WCF 4.5
  • More simplified generated configuration
  • Support for Intellisense and Tooltip
  • Multiple Authentication Type support
  • Introducing BasicHttpsBinding
  • A single WSDL file
  • Caching ChannelFactory
  • and more…

4. 3 Simple Ways to generate proxy in WCF

Primarily describing different ways to generate proxy in Windows Communication Foundation, this tutorial provides complete code for given example with screenshots. Starting from creating a simple WCF Service and later on using 3 different options to generate proxy in step by step manner as:

  1. Creating a WCF Service
  2. Hosting in a Console Application
  3. Generating Proxy using different options.

Options discussed here to generate proxy are:

  • Adding Service Reference
  • Implementing ClientBase<T> class
  • Using SvcUtil.exe Tool

Although we can use other means (i.e. using JavaScript) to generate proxy but here we are limited to above three options.

5. Difference between DataContract and MessageContract in WCF

Although we have discussed all different available contracts (including behavioral and structural contracts) in Windows Communication Foundation in this WCF blog, but focus in this WCF tutorial is limited to the difference between DataContract and MessageContract. Both of these contracts are structural contracts compliment each other serving different purposes. We cannot use both together in same scenario.

Point to understand here is that DataContract gives us control over SOAP message body content only and when using MessageContract, we have more control over SOAP message including body, header etc. So, this article takes an WCF Service as example and uses both DataContract as well as MessageContract separately to display control over SOAP message clearly explaining the difference.

Finally, I believe that you must be enjoying your relation with WCF Tutorial and this relationship will grow and prosperous more in this new year 2015. I am also determined to provide you will more helpful material on Windows Communication Foundation along with Free WCF Online Tests to validate your knowledge.

Important Note: Soon you will find a complete Online Practice Exam for Microsoft WCF Certification Exam: 70-487 (Developing Windows Azure and Web Services). It will be very beneficial for users planning to appear for actual certification.

Once again thanks all of you for your valuable feedback and support. Have a very Happy New Year 🙂

Message Exchange Patterns in WCF

In Windows Communication Foundation, both parties (i.e. a service and client) communicate with each other and exchange messages using a certain pattern known as Message Exchange Pattern (MEP). WCF supports three different types of MEPs (Message Exchange Patterns).

  • Request-Reply
  • One-Way
  • Duplex

In this WCF Tutorial Series, we will explore all three Message Exchange Patterns step by step with the help of sample code.

Request-Reply Message Exchange Pattern:

Windows Communication Foundation uses Request-Reply as default pattern for communication. In this pattern, when a service operation is called, it always generate a response message to caller (i.e. a client). The client will receive a response even if the service operation has void return type (receiving an empty SOAP body in this case).

A client always waits for a reply from service for certain time (i.e. ReceiveTimeout) and then execute the following piece of code. Default value for ReceiveTimeout is one minute, after that it throws an exception of type TimeoutException.WCF Request-Reply MEP

Almost all WCF Bindings support Request-Reply MEP except the followings:

  • NetMsmqBinding
  • NetPeerTcpBinding

Because Request-Reply is the default Message Exchange Pattern in WCF, so we don’t need to do anything to enable it. But for the purpose of understanding, we can explicitly set it enabled as follows:

[ServiceContract]
public interface RequestReplyMEPService
{
           [OperationContract(IsOneWay = false)]
           void SaveData(string value);
}

One-Way Message Exchange Pattern:

In certain scenarios, when we are not interested to receive response message back, instead just wanted to execute a certain business functionality by sending a message to WCF service. For example, we wanted to execute a long running business process or want queued message delivery. WCF provides One-Way Message Exchange Pattern (MEP) to fulfill such scenarios.WCF One-Way MEP

In One-Way MEP, client doesn’t need to wait for response after sending message to WCF service. Even if some error occurs in communication, WCF Service doesn’t send any response back. That’s why One-Way Message Exchange Pattern provides no support for followings in service operations:

  • no output parameters
  • no reference parameters
  • no return value

All WCF bindings support One-Way Message Exchange Pattern. In order to enable One-Way Message Exchange Pattern in WCF, do the follows:

[ServiceContract]
public interface OneWayMEPService
{
           [OperationContract(IsOneWay = true)]
           void SaveData(string value);
}

Duplex Message Exchange Pattern:

Duplex “as it’s name indicates” is a two-way message channel. In certain scenarios, we want to get a confirmation notification back from WCF service as an operation completes at service end. In more simple words, we can say that both service as well as client can send messages to eachother when using Duplex MEP. So, this message sending in duplex pattern can be request-reply (synchronous) or one-way (asynchronous).

Below diagrams further enhances the concept of Duplex MEP.Duplex (Request-Reply) MEP

Duplex (One-Way) MEP

In order to implement Duplex pattern for message exchange, CallbackContract is additionally required along with ServiceContract. We need to associate CallbackContract with ServiceContract through CallbackContract property of our ServiceContract.

For example, we have a CallbackContract named “DuplexMEPServiceCallback” as follows:

//CallbackContract
  public interface DuplexMEPServiceCallback
  {
          [OperationContract(IsOneWay = true)]
          void ProcessComplete(int value);
  }

So, we will associate above CallbackContract to following ServiceContract named “DuplexMEPService” through CallbackContract property as follows:

  [ServiceContract(CallbackContract = typeof(DuplexMEPServiceCallback))]
  public interface DuplexMEPService
  {
           [OperationContract(IsOneWay = true)]
           void CallProcess(string value);
  }

Duplex MEP being a two-way message channel works with few bindings that has bi-directional capabilities like wsDualHttpBinding. So, endpoint will be defined
as follows:

<endpoint address=”” binding=”wsDualHttpBinding” contract=”DuplexMEPService”>

There are always some concerns while using Duplex MEP that must be considered or addressed as:

  • Maintaining a long-running session between parties can create scalability problems.
  • It requires a connection back to client which is always not possible.

We have discussed in details about all three Message Exchange Pattern in this WCF Tutorial with respective scenarios. Your feedback is really important for me. You can leave your feedback about how fruitful the content is? Enjoy WCF Service Programming.

To test and further enhance your WCF skillsWCF Online Test

Other WCF and related Tutorials:

Top 10 Interview Questions and Answers Series:

Transport Level Security Vs Message Level Security in WCF

Core security concepts supported by WCF – Windows Communication Foundation are Confidentiality, Integrity, Auditing, Authentication and Authorization. In Windows Communication Foundation, security can be configured at two different levels:Transport Vs Message Level Security in WCF

  • Transport Level Security
    It secures the actual transport (i.e. the pipe) over which the message passes through from client to a service. For example it uses SSL (Secure Socket Layer) to ensure point-to-point protection.
  • Message Level Security
    It secures the message itself that is being transported from client to a service and vice versa.

In this WCF Tutorial, we will dive deeper to understand the difference between Transport Level Security and Message Level Security in WCF (Windows Communication Foundation).

Recommended Scenarios for Transport and Message Level Security:

Transport Level Security doesn’t support scenarios when Intermediaries involved. It only support sending a message directly from client to WCF Service without an intermediate system. It’s suited when both client and service resides on same intranet.

On the other hand, actual message is secured in Message Level Security, it support intermediaries. No problem at all in scenarios even if message routed through multiple intermediate systems.
Below you can find advantages/disadvantages for both these security levels that will help to understand  the difference between Transport Level Security and Message Level Security.

Transport Level Security

Message Level Security

Advantages:
  • As Transport Level Security secures the network protocol, so no extra coding required.
  • As client and service doesn’t need to understand WS-Security specification results support for interoperability.
  • Improved performance can be achieved by using hardware accelerators.
  • As the message is secured (signed and encrypted) while transmitting through the network, any intermediate hop in the network has no impact on security.
  • Being transport-independent, it can support multiple transport options.
  • Supports wide range of security options, even we can implement custom security.
Disadvantages:
  • Lacks support for intermediate systems because it’s point to point and protects the “pipe” between a single client and a service.
  • Security options are comparatively less due to protocol security limitations.
  • Every individual Message is secured means there is a cost to encrypt a message at one side and decrypt on the other resulting in reduced performance.
  • Lacks Interoperability. It demands both client and service should support WS-Security specification, so no support for applications developed in older technologies like ASMX.

Other Related Articles:

Top 10 Interview Questions and Answers Series:

Understanding Fault Contract in WCF

In previous WCF tutorials, we learnt about different WCF Contracts including Behavioral (Service Contract, Operation Contract) and Structural (Data Contract and Message Contract). In this post, we will learn about another behavioral Contract i.e. Fault Contract.

What is a Fault Contract?

In WCF (Windows Communication Foundation), we will not expose exception directly to client if it occurs at service level. There is a valid reason for that, “WCF exceptions are basically CLR exceptions containing internal details of service code (e.g. stack trace etc), so it doesn’t make sense to expose it outside CLR“.
In Windows Communication Foundation, Fault Contract is used to return error details to the other party i.e. client. Fault Contract is a behavioral contract that contains the details of possible exception(s) that might occur in a service code.

In order to fully understand the idea, let’s create a WCF Service that generate exception.

[ServiceContract]
public interface ISimpleService
{
               [OperationContract]
               string SimpleOperation();
}
public class SimpleService : ISimpleService
{
              public string SimpleOperation()
             {
                  //Some code here…
                  throw new Exception(“Exception occurred at service level : SimpleOperation error”);
             }
}

While consuming this service on client side, we are expecting above given exception message “Exception occurred at service level : SimpleOperation error” when SimpleOperation is called. But we will get the following error in all cases.

“The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults(either from ServiceBehaviorAttribute or from the configuration behavior) on the server in order to send the exception information back to client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs”

So, in order to avoid the above generic error and get a customized error message, we will modify our service code as follows:

public string SimpleOperation()
{
          //Some code here…
          throw new FaultException(“Exception occurred at service level : SimpleOperation error”);
}

Now, if we run the client application and call the WCF Service, we will get a proper meaningful error as:

Exception occurred at service level : SimpleOperation error

WCF also facilitates us to use more professional approach by creating our own Custom Exception type and return using Fault Contract. For example, we can create our custom type say “CustomFaultDetail” as follows:

[DataContract]
public class CustomFaultDetails
{
            [DataMember]
            public string ErrorID { get; set; }
           
            [DataMember]
            public string ErrorDetails { get; set; }
}

Note: Custom fault type is attributed as a Data Contract. We have already discussed about Data Contracts in WCF in previous post.

So, above contract and implementation code will be updated accordingly.

[ServiceContract]
public interface ISimpleService
{
               [OperationContract]                [FaultContract(typeof(CustomFaultDetails))]
               string SimpleOperation();
}
public class SimpleService : ISimpleService
{
              public string SimpleOperation()
             {
                  Try{                         
                                      //Do something……                          
                    }catch()
                   {
                            CustomFaultDetails ex = new CustomFaultDetails();
                            ex.ErrorID = “12345“;
                            ex.ErrorDetails = “Specific error details here.“;
                            throw new FaultException(ex,“Reason: Testing…..“);
                  }

             }
}

In this way we can pass more meaningful details about the error to client.

Now, we have covered all types of contracts in WCF including Behavioral(Service Contract, Operation Contract, Fault Contract) as well as Structural (Data Contract and Message Contract).

Other WCF and related Tutorials: