Building Dynamic Services Using Asp.net Web Api and Odata

Slalom Consultant Joel Forman

Slalom Consultant Joel Forman is a Solution Architect specializing in cloud computing.

Over the past few years I have been building more and more RESTful services in .NET. The need for services that can be used from a variety of platforms and devices has been increasing. Often times when we build a service layer to expose data over HTTP, we may be building it for one platform (web) but know we know that another platform (mobile) could be just around the corner. Simple REST services returning XML or JSON data structures provide the flexibility we need.

I have been very excited to follow the progress of ASP.NET Web API in MVC4. Web API makes creating RESTful services very easy in .NET, with some of the same ASP.NET MVC principals that .NET developers have already become accustomed to. There are some great overview and tutorials on creating ASP.NET Web APIs.  I encourage anyone to read through the tutorial Your First Web API for an initial overview.

Another important area to address when it comes to writing RESTful services is the topic of how to provide the ability for consumers to query data. How consumers want to retrieve and interact with the data is not always known, and trying to support a variety of parameters and operations to expose the data in different ways could be challenging. Enter the Open Data Protocol. OData is a new web standard for defining a consistent query and update language using existing web technologies such as HTTP, ATOM and JSON. For example, OData defines different URI conventions for supporting query operations to support the filtering, sorting, pagination, and ordering of data.

Microsoft has been planning on providing support for OData in ASP.NET Web API. In the past few weeks, Microsoft released an OData Package for Web API via NuGet enabling the ability for OData endpoints that support the OData query syntax. Here is a blog post that describes the contents of that package in more detail.

Let’s take a closer look at how to take advantage of this new OData library. In this example below (being a consultant), I build a simple API for returning Projects from a data repository.

Web API provides an easy development model for creating an APIController, with routing support for GET, POST, PUT, and DELETE automatically set up for you by the default route for Web API. When you create a default APIController, the GET method returns an IEnumerable<T> where T is the model for your controller. For example, if you wanted a service to return data of type Project, you could create a ProjectsAPIController and your GET method would return IEnumerable<Project>. The Web API framework handles the serialization of your object to JSON or XML for you. In my example running locally, I can use Fiddler to make requests against my REST API and inspect the results.

Query: /api/projects

After adding a reference to the Microsoft ASP.NET Web API OData package via NuGet, there are only a couple small tweaks I need to make to my existing ProjectsAPIController to have the GET method support OData query syntax.

  1. Update the return type of your query (and underlying repository) to be IQueryable<T>.
  2. Add the [Queryable] attribute to your method.

What is happening here is that by returning an IQueryable<T> return type, we are deferring the execution of that query. The OData package then, through the Queryable attribute, is able to interpret the different query operations present on the request and via an ActionFilter apply them to our Query before the query is actually executed.  As long as you are able to defer the actual execution of the query against your data repository in this fashion, this practice should work great.

Let’s try out a couple of queries in Fiddler against my API to show OData in action.

Query: /api/projects?$filter=Market eq ‘Seattle’

Query: /api/projects?$orderby=StartDate desc&$top=5

The list of OData URI conventions for query syntax is extensive, and can be very powerful.  For example, the TOP and SKIP parameters can be used to provide consumers with a pagination solution to large data sets.

One key concept to understand with OData with Web API is understanding the capabilities and limitations around when the query parameters need to be applied against your data repository. For instance, what if the data repository is not able to support returning an IQueryable<T> result? You may be working with a repository that requires parameters for a query up front. In that case, there is an easy way to access the OData request, extract the different parameters supplied, and apply them in your query up front.

The mapping of operations and parameter to your repository’s interface may not be ideal, but at least you are able to take advantage of OData and provide a standards-based experience to your consumers.

Support for building RESTful APIs in .NET just keeps getting better and better. With ASP.NET Web API and the upcoming support for OData in Web API, you can build dynamic APIs for multiple platforms quickly and easily.

Webinar: Accelerating SharePoint for Mobile Solutions on the AWS Cloud

Slalom Consultant Joel Forman

Slalom Consultant Joel Forman specializes in cloud computing and the Windows Azure Platform.

I wanted to take the opportunity to post about an exciting upcoming live webinar that is being co-delivered by Slalom Consulting and Amazon Web Services entitled Accelerating SharePoint for Mobile Solutions on the AWS Cloud.

On Wednesday, August 15th at 10:00 AM PST, we will bring several emerging topics together around mobility and the cloud. You will have the opportunity to learn more about how to make SharePoint applications available to your mobile users using the AWS cloud directly from an AWS Solution Architect. Then, we will demonstrate how they can quickly and securely mobilize SharePoint content with our SharePoint Mobile Accelerator. The Accelerator is a framework that can target both on-premise and cloud SharePoint implementations, and allows for rapid development of custom iPhone & iPad applications to enable your growing mobile workforce while maintaining corporate security standards.

Here are the individuals that will be presenting during this live session: Read more of this post

Your Future in the Clouds: How Cloud Computing is Transforming the IT Landscape

Slalom Consultant Joel Forman

Slalom Consultant Joel Forman specializes in cloud computing and the Windows Azure Platform.

Since 2008, I have been working on building applications on the cloud.  Over the past four years, I have seen terms such as “platform-as-a-service”, “multi-tenancy”, “elastic compute”, and “hybrid-cloud” become part of my everyday vocabulary. Sometimes I lose sight of the fact that the cloud itself is still an emerging space. There are many companies today who have yet to explore the opportunities that may exist for their organization in the way of cloud services. And there are many more individuals who hear the buzzwords are not quite sure what they mean and why they should care about them.

Dan Maycock, fellow Slalom consultant and national lead for technology strategy, and I recently took a step back and published a white paper entitled Your Future in the Clouds: How Cloud Computing is Transforming the IT Landscape. Geared towards the cloud newbie, the paper talks about cloud computing, some of its key concepts and benefits, and highlights a few of the projects Slalom has recently completed in the space. We try to provide a simple perspective on topics such as Computing Models, Storage, Security, and countless others.

Recently our paper has been featured on CIO.com! We look forward to helping you navigate the cloud and realize the opportunities that exist in your organization.

Building Windows Azure Projects with Team Foundation Service

Slalom Consultant Joel Forman

Slalom Consultant Joel Forman specializes in cloud computing and the Windows Azure Platform.

In the fall of 2011, Microsoft announced a preview of the Team Foundation Service, a cloud-based version of Team Foundation Server (TFS) powered by the Windows Azure Platform. This next generation of TFS doesn’t require any server component, as end-users can connect to the service over the internet from Visual Studio, and via the web-based administration console.

The preview initially enabled features software projects such as Work Item Tracking and Source Control. A subsequent release of the preview enabled the Build feature. The service now provides a pool of virtual machines running in Windows Azure that are standing by ready to compile, test, and package your applications. Having used the initial service for a couple of projects already, I was eager for the Build service to become available. To me, this rounded out the offering, and allowed me to run a TFS project with truly no on-premise computing need. Read more of this post

Ramping Up on the Windows Azure Platform: 200 Level

I was recently asked to put together some material for consultants with the goal of getting to a “200 Level” of knowledge on the Windows Azure Platform and its breadth of capabilities. I thought this would be an opportune time to revamp a previous “getting started” post that I did with some updated content. Below is a 10-hour self-paced training plan, design for bringing someone up to that 200 level…

Read: Understanding the Different Platform Components (~1 hour)

Take a few minutes to read a brief overview of some of the different features of the Windows Azure Platform. Think of these as building blocks. They can be used individually or together to solve problems and build applications. Read more of this post

Recent Windows Azure Project Highlights: Media, WS-Fed and More…

Slalom Consultant Joel Forman

Slalom Consultant Joel Forman specializes in cloud computing and the Windows Azure Platform.

I haven’t been blogging as much in the past few months, but I have a good excuse. I have been heads down over the last few months working with several clients on different, innovative projects that leverage the Windows Azure Platform. From media processing to federated authentication to scalable services and database, Slalom Consulting has been doing great work in the cloud.

Project Highlight: Cloud-based Tax Form Application
Slalom has engaged with an existing tax and accounting firm to build a web-based tax form application that leverages several features of the Windows Azure Platform. The application is an ASP.NET MVC3 application running in Windows Azure compute as a Web Role. Information collected by the application is stored in a SQL Azure relational database. Asynchronous operations, such as data imports and exports, are executed in Windows Azure Compute as Worker Roles, and those operations are triggered by messages stored in Windows Azure Queues. Furthermore, documents related to the tax collection process are securely stored as BLOBs in BLOB Storage.

The web application is configured against the Access Control Service to allow users to authenticate via 2 identity providers. Employees of the firm, who manage their tax clients, authenticate with their corporate credentials via Active Directory Federation Services. Clients themselves authenticate via custom client identities. The client identity store sits behind a custom STS (security token service), also an ASP.NET MVC3 application leveraging Windows Identity Foundation, and running in Windows Azure compute. Read more of this post

Windows Azure Real World Guidance Article on MSDN

Slalom Consultant Joel Forman

Slalom Consultant Joel Forman specializes in cloud computing and the Windows Azure Platform.

I am pleased to announce that fellow Slalom colleague Stephen Roger and I recently had an article we wrote published on MSDN. Microsoft supports a collection of articles on MSDN called Real World Windows Azure Guidance, where people from the technology community can share real experiences on using the Windows Azure platform.

Our article, entitled Considerations When Choosing a Web Role Instance Size: How small should I go?, attempts to look at the topic of choosing a virtual machine size for your web applications when starting on Windows Azure from a cost and scalability angle. In the article we provide guidance on sizing decisions for web roles by:

  • Comparing performance of a web application under load for different instance sizes;
  • Factoring in a hypothetical usage pattern to understand scaling implications for instance sizes; and
  • Evaluating cost when scaling for different instance sizes.

Please check out the article when you get a chance!

Windows Azure Platform: Januaury 13th Links

Slalom Consultant Joel Forman

Slalom Consultant Joel Forman specializes in cloud computing and the Windows Azure Platform.

Happy New Year everyone! My first blog of 2012 highlights some of the resources and news around the Windows Azure Platform that caught my eye over the last couple months. Again, this is not a comprehensive list, but pieces that caught my eye in particular. Read more of this post

Slalom and the Windows Azure Circle Program

Slalom Consultant Joel Forman

Slalom Consultant Joel Forman specializes in cloud computing and the Windows Azure Platform.

Slalom Consulting recently announced via this press release that it has been selected by Microsoft to join the Windows Azure Circle Program.  As Microsoft’s 2011 Online Services Partner of the Year, we continue to invest in our practice areas to deliver Microsoft Cloud Services to our clients.

What is the Windows Azure Circle Program?

Microsoft has created the Windows Azure Circle program to create a healthy partner ecosystem around Windows Azure and to ensure the success of System Integrator (SI) partners worldwide.  This program creates a partnership between Microsoft and the SI that will together bring great value in the delivery of Azure services to customers.  Entry into the program requires commitments from the partner to build a strong Windows Azure practice.  These commitments range from training architects, developers, and sellers on the Windows Azure Platform, to goals around practice and customer development.  In return, partners receive several benefits from Microsoft such as internal briefings, development and test platform resources, and the ability to deliver incentive programs sponsored by Microsoft. Read more of this post

Windows Azure Readiness with Slalom Consulting

Slalom Consultant Joel Forman

Slalom Consultant Joel Forman specializes in cloud computing and the Windows Azure Platform.

Last week I blogged about how you can learn how your company can leverage Windows Azure in a session with Slalom Consulting. Take that design session to the next level with Slalom Consulting and our Windows Azure Readiness offering to build a pilot on Windows Azure around your application.

Why Meet?
Slalom helps organizations leverage the Windows Azure platform, turning the focus onto applications that provide business value instead of the infrastructure for running them. Companies can reduce management costs, increase productivity, and take advantage of new economics.

Slalom’s Windows Azure Readiness offering allows an organization to quickly understand the features and benefits of the Microsoft Windows Azure Platform, brainstorm use of the platform within your organization, and apply cloud development principles via a proof of concept exercise.

Read more of this post

Follow

Get every new post delivered to your Inbox.

Join 126 other followers

%d bloggers like this: