Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Building Web Services with Windows Azure (new)
Building Web Services with Windows Azure (new)

Building Web Services with Windows Azure (new): Quickly develop scalable, REST-based applications or services and learn how to manage them using Microsoft Azure

Arrow left icon
Profile Icon Nikhil Sachdeva Profile Icon Kaufman
Arrow right icon
€8.99 €29.99
Full star icon Full star icon Full star icon Full star icon Empty star icon 4 (3 Ratings)
eBook May 2015 322 pages 1st Edition
eBook
€8.99 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Nikhil Sachdeva Profile Icon Kaufman
Arrow right icon
€8.99 €29.99
Full star icon Full star icon Full star icon Full star icon Empty star icon 4 (3 Ratings)
eBook May 2015 322 pages 1st Edition
eBook
€8.99 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€8.99 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Building Web Services with Windows Azure (new)

Chapter 1. Getting Started with the ASP.NET Web API

ASP.NET Web API is a framework for building HTTP Services. It is part of the ASP.NET platform, which is a free web framework for building websites and services.

Microsoft Azure makes building web services extremely easy. It provides the backbone for hosting scalable Web APIs and then efficiently managing and monitoring them.

In this chapter, we get to know the ASP.NET Web API framework. We delve into the fundamentals of the components that encompass the ASP.NET Web API, walk through the request-response pipeline of ASP.NET Web API, and also talk about the main features provided by the framework that make development of ASP.NET Web API a breeze. We then begin with the essential step of creating our first ASP.NET Web API and then deploy it in Microsoft Azure.

The ASP.NET Web API framework

ASP.NET Web API provides an easy and extensible mechanism to expose data and functionality to a broad range of clients, including browsers and modern web and mobile apps. The most significant aspect of ASP.NET Web API is that it is targeted to enable support for HTTP and RESTful services. In this section, we will discuss the nuts and bolts of the Web API framework.

Note

In the context of this book, the words ASP.NET Web API, Web API, and HTTP Services represent the same thing unless explicitly mentioned. This chapter assumes that the reader has knowledge about HTTP, REST, and Web API, in general. For more information on these technologies, please refer to the introduction chapter of this book.

Background

Before we delve into the building blocks and design principles behind ASP.NET Web API, it is important to understand that ASP.NET Web API is an evolution of the existing continuous Microsoft efforts to enable support for HTTP Services. A timeline of events that describe this evolution are outlined next.

Windows Communication Foundation (WCF) (https://msdn.microsoft.com/en-us/library/ms731082%28v=vs.110%29.aspx) was launched with .NET 3.0 for SOAP-based services; the primary aim was to abstract the transport layer and enable support for the WS-* protocol. No HTTP features were enabled except HTTP POST for requests

In NET 3.5, WebHttpBinding (https://msdn.microsoft.com/en-us/library/system.servicemodel.webhttpbinding%28v=vs.110%29.aspx) was introduced in WCF with the intent to support services that were not based on SOAP. It allowed systems to configure endpoints for WCF services that are exposed through HTTP requests instead of SOAP messages. The implementation was very basic and...

Building blocks

As described in the previous section, ASP.NET Web API is built on top of existing frameworks and technologies. Web API leverages features from ASP.NET MVC, the core ASP.NET framework, and the .NET framework to reduce the overall learning curve for developers and at the same time provides abstraction to make programming easier. The following figure highlights the key features that make up the ASP.NET Web API framework.

Building blocks

Note

ASP.NET Web API leverages some standard features from the ASP.NET MVC framework. Though expertise in ASP.NET MVC is not a requirement for developing HTTP Services using ASP.NET Web API, a fundamental understanding of the ASP.NET MVC framework and the MVC design pattern is useful. More information about the ASP.NET MVC framework is available at http://www.asp.net/mvc.

Design principles behind the ASP.NET Web API

Now that we understand the intent behind ASP.NET Web API, let's discuss some design principles on which ASP.NET Web API is based:

  • Distributed by design: ASP.NET Web API considers HTTP as a first-class citizen and has inherent support for REST. It enables a framework for creating distributed services that leverage HTTP features such as stateless, caching, and compression.
  • Russian Doll Model: This is also called the Matryoshka doll model, which refers to a set of wooden dolls of decreasing sizes placed one inside the other. Architecturally, it denotes a recognizable relationship of nested objects (object within an object). The ASP.NET Web API messaging handlers leverage this principle to define the request-response pipeline. Each handler in the pipeline is responsible for processing the incoming request and then delegating the request to another handler. When a request reaches a handler, it may opt to process it, validate it, and then delegate...

Application scenarios

As mentioned before, ASP.NET Web API enables customers to easily and rapidly develop HTTP-based services that can result in new business opportunities or improved customer satisfaction. Some of these scenarios are described here:

  • Mashup: This refers to accessing content from more than one service and then creating a new service typically via a user interface. For example, multiple services exposed by the Bing Maps API can be used by a consumer to create a map-plotting user interface that can show the location of nearby location on a map.
  • Smartphone apps: This is a no-brainer; the mobile app market is one of the most booming markets today. An independent survey suggests that around 56 billion apps were downloaded in 2013 generating revenue of around $20-25 billion, and this number is only going to increase in the coming years. ASP.NET Web API provides multiple client libraries to offer developers with quick and easy ways to create HTTP Services. Moreover, Microsoft Azure...

Behind the scenes with the ASP.NET Web API

Let's talk about some of the internal workings of ASP.NET Web API and how a request is received and a corresponding response generated.

Anatomy of the API of ASP.NET Web API

Before we understand the request and response lifecycle within ASP.NET Web API, it is important to comprehend some of the principal types and their usage within the pipeline.

The core assemblies for ASP.NET Web API can be installed using the Microsoft.AspNet.WebApi NuGet package, which is distributed under the MS license, this will install all the required dependencies to develop an ASP.NET Web API service.

Note

NuGet is the package manager for the Microsoft development platform, including .NET. The NuGet client tools provide the ability to produce and consume packages. NuGet is installed as part of the Visual Studio 2013 release. To know more about NuGet, visit https://www.nuget.org/.

To install the runtime packages via the NuGet Package Manager Console in Visual Studio use...

Routing and dispatching

The routing and dispatching stage primarily involves the execution of a series of message handlers, which process the incoming request and then delegate them to the next message handler for processing. In earlier versions of ASP.NET Web API, we could only configure message handlers globally per application. All the message handlers were added to the HttpConfiguration.MessageHandlers collection and were executed for each request. The global configuration was enabled using the Register method in the WebApiConfig.cs file, which gets added when creating a new ASP.NET Web API project. We talk more about the WebApiConfig and Register method in the Creating our first ASP.NET Web API section. The following snippet show a sample Register method definition:

public static void Register(HttpConfiguration config)
{

    config.Routes.MapHttpRoute(
       name: "DefaultApi",
       routeTemplate: "api/{controller}/{id}",
       defaults: new { id = RouteParameter...

Creating our first ASP.NET Web API

In this section, we will start building our Web API, covering the necessary environment required for creating a Web API. We will also discuss our problem scenario, and then create a Web API from scratch. We will then delve into the details of Microsoft Azure websites and deploy our first Web API in Microsoft Azure.

Prerequisites

The following must be configured to run the example scenarios we discuss in this and following chapters:

  • Developer machine: We need a development environment that can support Microsoft Visual Studio and ASP.NET Web tools. Although we can create ASP.NET Web API solutions from a local PC, for the purpose of this book, we will host a new virtual machine in Microsoft Azure and use it as our development environment. Setting up and managing an environment on Microsoft Azure is so straightforward and elegant, that it is now used as a preferred way to develop applications.
  • A Microsoft Azure subscription: We need a Microsoft Azure subscription...

Testing the Web API

Now that we have a Web API created, we will look at options to validate our Web API functionality. Testing is a crucial stage in the creation of Web API development and publishing. There are a couple of different ways of doing this. We can just test it by requesting the URL in a browser or write code and leverage the System.Net.HttpClient type. This section discusses both of these approaches.

Testing in a browser

Testing a Web API is as simple as developing it, since each action in a Web API controller represents a resource, we can just type the URL of the resource and fetch the results.

  1. Press F5 in Visual Studio to launch the Web API in a browser.
  2. Visit the following URL:

    http://localhost:<PORT>/api/package/1

    Note

    Note that the port will be allocated by IIS Express and will be different for each installation.

  3. This yields a result similar to the following in the browser:
    {
        "Id": 1,
        "AccountNumber": "43a2a3eb-e0b8-4840-9e5e-192214a79d58...

Committing changes to Git

In the previous section, we built and tested our Web API. Now, we discuss how to use Visual Studio Online and Git for source control management. Note that this section assumes that we have a Git repository created and available. It does not give a walkthrough of setting up a Git repository within VSO.

Note

The Microsoft Virtual Academy has an excellent tutorial for using Visual Studio Online with Git it is highly recommended to understand these concepts before proceeding with this section: http://www.microsoftvirtualacademy.com/training-courses/using-git-with-visual-studio-2013-jump-start.

We will now commit the change to Visual Studio Online. Visual Studio 2013 provides a rich integration with Git so we can commit the changes without opening the Git command prompt:

  1. Right-click on the Contoso.Transport.Service solution file in the Solution Explorer, and click on Add Solution to Source Control.
  2. A dialog box is displayed with options for available source control systems...

Deploying the ASP.NET Web API using Azure Websites

Microsoft Azure Websites is a Platform as a Service (PaaS) offering from Microsoft, which allows publishing web apps in Azure. The key focus when building Microsoft websites is to enable a true enterprise-ready PaaS service by allowing rapid deployment, better manageability, global scale at high throughput, and support for multiple platforms. The development of Azure Websites started about 3 years ago under the internal project name Antares with the primary intent to create a cheap and scalable web hosting framework for Microsoft Azure. The main target was shared and cross-platform hosting scenarios. The first preview release for Azure Websites came out in June 2012 and went General Availability (GA) in mid-2013.

Note

Azure Websites was recently renamed and is now part of Azure App Services. REST based service development is now referred to as API apps. For the scope of this book, we will focus on the existing service implementation. To learn...

Continuous Deployment using Azure Websites

In the previous section, we used Visual Studio tools to deploy our Web API in Microsoft Azure Websites. The Visual Studio deployment option works well for one-off deployments or small development projects. However, in real-world scenarios, customers prefer integrating builds with automated deployments. Azure Websites provides continuous deployment from source code control and repository tools such as BitBucket, CodePlex, Dropbox, Git, GitHub, Mercurial, and Team Foundation Server. We can, in fact, do a Git deployment from a local machine!

For the purpose of this sample, we use VSO and Git as our repository. Let's take a look at how we can configure Visual Studio Online for our Continuous Deployments (CD):

  1. Go to the Azure portal and browse to the Azure Website we just created. From the dashboard, select setup deployment from source control. When using the new preview portal, this option will be in the Deployment section as Set up continuous deployment...

Summary

This chapter provided an overview of the what, why, and how of an ASP.NET Web API. ASP.NET Web API is a next generation service that enables support for a first-class modern HTTP programming model. It provides abundant support for formats and content negotiation, and request validation.

We talked about the foundational elements of a Web API. We then discussed its usage scenarios and components, and also discussed the classes that make up the API. We went through the request-response pipeline and walked through the message lifecycle of a request. We then created our first simple Web API for a simplified customer scenario and walked through its development, testing, and deployment using Azure Websites. In the next chapter, we will look into advanced capabilities of ASP.NET Web API, and see how these capabilities can be used to customize different aspects of the ASP.NET Web API request-response pipeline.

Left arrow icon Right arrow icon

Description

If you are a .NET developer who wants to develop end-to-end RESTful applications in the cloud, then this book is for you. A working knowledge of C# will help you get the most out of this book.

Who is this book for?

If you are a .NET developer who wants to develop end-to-end RESTful applications in the cloud, then this book is for you. A working knowledge of C# will help you get the most out of this book.

What you will learn

  • Build RESTful services using the ASP.NET Web API and Microsoft Azure
  • Host and monitor applications in Azure Websites and Azure Mobile Services
  • Manage Web APIs using Azure API Management
  • Utilize Azure Service Bus to provide elasticity to your applications as well as publish and subscribe features
  • Utilize the Microsoft Azure Platform as a Service (PaaS) component in your custom solutions
  • Get to grips with the basic characteristics of distributed systems
  • Use Entity Framework as the data model
  • Leverage your cloudbased storage and discover how to access and manipulate data in the cloud
  • Explore the NoSQL options available in Microsoft Azure

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : May 27, 2015
Length: 322 pages
Edition : 1st
Language : English
ISBN-13 : 9781784395698
Vendor :
Microsoft
Languages :
Concepts :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : May 27, 2015
Length: 322 pages
Edition : 1st
Language : English
ISBN-13 : 9781784395698
Vendor :
Microsoft
Languages :
Concepts :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 98.97
Building Web Services with Windows Azure (new)
€36.99
Microsoft Azure Security
€24.99
Learning Microsoft Azure
€36.99
Total 98.97 Stars icon
Banner background image

Table of Contents

11 Chapters
Introduction Chevron down icon Chevron up icon
1. Getting Started with the ASP.NET Web API Chevron down icon Chevron up icon
2. Extending the ASP.NET Web API Chevron down icon Chevron up icon
3. API Management Chevron down icon Chevron up icon
4. Developing a Web API for Mobile Apps Chevron down icon Chevron up icon
5. Connecting Applications with Microsoft Azure Service Bus Chevron down icon Chevron up icon
6. Creating Hybrid Services Chevron down icon Chevron up icon
7. Data Services in the Cloud – an Overview of ADO.NET and Entity Framework Chevron down icon Chevron up icon
8. Data Services in the Cloud – Microsoft Azure Storage Chevron down icon Chevron up icon
9. Data Services in the Cloud – NoSQL in Microsoft Azure Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
(3 Ratings)
5 star 66.7%
4 star 0%
3 star 0%
2 star 33.3%
1 star 0%
Kerry newton Dec 27, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
No idea it was a gift for programming son
Amazon Verified review Amazon
Vivi Banks Mar 31, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Excellent read
Amazon Verified review Amazon
.NET Dev Sep 02, 2015
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
I am new to this technology and thought a step by step guide would help. I have not been able to obtain the sample code despite repeated e-mails to the publisher. The instructions as to how to interact with Azure are obscure -- no explanation of why or what you are configuring or how the various different parts play together. The wheels fell off at the end of chapter 2 -- there was no getting past the broken instructions there. Prepare for frustration beyond the norm.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.