Exam 70-487: Accessing Data - How to choose the Appropriate Data Access Technology - WCF Data Services?

The two Data Access technologies we have studied so far (ADO.NET and Entity Framework) really deal with our Applications accessing back end data within the context of enterprise network, even if the application is an internet facing application.

Since different applications are written in different programming languages, they often cannot communicate with each other out of the box. So,
if you want to make the application available to outsiders, the only option we used to have was to build a web service.

A Web service enables this communication by using a combination of open protocols and standards. Once upon a time, this was mostly done with XML, SOAP and WSDL. A Web service uses XML to tag data, SOAP to transfer a message and finally WSDL to describe the availability of services.

But, during the 2000-2010 decade, the development landscape underwent significant changes with the formulation of the following protocols and architectural styles:
Representational State Transfer (REST): First defined by Roy Fielding in 2000,is a software architectural style that defines a set of constraints to be used for creating web services.

JavaScript Object Notation (JSON): first specified and popularized by Douglas Crowford in 2001, is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming

Open Data protocol (OData): Initiated by Microsoft in 2007, is a standard that defines a set of best practices for building and consuming REST-ful APIs.OData uses the entity-relationship conventions of the Entity Data Model (Read more about it here)to expose resources as sets of entities that are related by associations.

WCF Data Services, a successor to or formerly known as the ADO.NET Data Services, is the main mechanism from Microsoft to expose the above technologies (REST, JSON, oData). Quite frankly, as an Architect, Developer or Engineer, you must master OData, REST, JSON in today's service oriented environment. WCF Data Services can expose data that originates from various sources as OData feeds.

But for now, we focus on WCF Data Services concept itself: In a typical scenario, you build a WCF Data Service by performing the following steps:

  1. Create an ASP.NET Web Application
  2. Use the Entity framework to define an EDM
  3. Add a Data Service to the Web Application (which is there just to host the application and expose it over the web)
  4. Enable access to the service
When to choose WCF Data Services as a data Access technology?
It provides several out-of-the box benefits that ADO.NET and Entity framework do not:
  • Data is exposed using OData, resources are addressable via URIs, meaning that anyone can consume them from any plateform and device.
  • WCF data services are accessed over HTTP, so someone can literally query your application without writing a single line of code.
  • Very powerful queries can be constructed with very simple semantics unlike the need to know T-SQL in the case of other Data Access technologies.
  • WCF Data Services provides a feature known as Interceptors, enabling to build a pretty sophisticated business logic.
Expect questions on the exam's Accessing Data's objective that test your knowledge on when to use WCF Data Services as opposed to ADO.NET.

Fast forward to 2018, I would like to say that Microsoft is now heavily investing in the ASP.NET WEB API as the technology of choice for creating Http Services. Sometimes in 2014, In a nutshell, Microsoft last announced it will shift its OData-related development tool efforts from WCF Data Services to ASP.NET Web API, moving WCF Data Services to open source for further development.

So while WCF Data Services is the focus in this exam, it is important to know that ASP.NET Web API is described by Microsoft as an ideal platform for creating RESTful applications on the Microsoft .NET Framework, from now on (this does not mean that WCF Data Services should be left alone, there are still scenario that warrant WCF Data Servcies, and a lot of it is in production). Microsoft will not, for instance be incorporating any OData 4.0 features into WCF Data Services because of technical issues in the design.

There is a separate objective in Exam 70-487 dealing with ASP.NET WEB API.

If you want to create a WCF Data Services feed for practice:
Download the NorthWind sample database (sql script) from nugget  and run the scripts in SSMS

  1. Open SSMS.
  2. Connect to the target SQL Server.
  3. Open the script in a new query window.
  4. Run the script.
Now you are ready to follow the above 4 steps to create your first service. Steps 1 and 2, are generally straightforward.

I have seen issues with step 3, whereby you don't see the WCF Data Service 5.6.4 template in Visual Studio 2017. If WCF data Service template is missing in your Visual Studio 2017, follow the solution here: https://developercommunity.visualstudio.com/content/problem/25983/wcf-data-service-template-missing-in-vs2017.html (Basically you have to download the template and put it in your local Item templates folder(EX: C:\Users\rawamba\Documents\Visual Studio 2017\Templates\ItemTemplates)).

After adding the WCF Data Services, you will need to add the reference to Microsoft .Data.Services from nugget: The Microsoft.Data.Services is a fully-featured server API for responding to OData queries and consuming/producing OData payloads. Supports OData v3. Targets .NET 4.0 or Silverlight 4.0.

The Final step is to set Read, Write or Both Access rights to entities as well as other settings. I do want to emphasize that Any client that can access the ASP.NET application can also access the resources exposed by the data service. 

In a production data service, to prevent unauthorized access to resources you should also secure the application itself. For more information, see Securing WCF Data Services.

EXAM Tip: The final thing to make sure you understand is the URI conventions for consuming a WCF Data Services and how to build a filter to retrieve data.  


References:
Creating WFC Data Services
Defining WCF Data Services
Configuring WCF Data Services:

Comments

Popular posts from this blog

Why can't Microsoft install IIS on Window Operating Systems by default?

Exam 70-487: Accessing Data - How to choose the Appropriate Data Access Technology - Entity Framework?

Exam 70-487: Accessing Data - How to choose the Appropriate Data Access Technology - Azure Cosmos DB?