Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
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 Kaufman Profile Icon Nikhil Sachdeva
Arrow right icon
R$50 per month
Full star icon Full star icon Full star icon Full star icon Empty star icon 4 (3 Ratings)
Paperback May 2015 322 pages 1st Edition
eBook
R$80 R$218.99
Paperback
R$272.99
Subscription
Free Trial
Renews at R$50p/m
Arrow left icon
Profile Icon Kaufman Profile Icon Nikhil Sachdeva
Arrow right icon
R$50 per month
Full star icon Full star icon Full star icon Full star icon Empty star icon 4 (3 Ratings)
Paperback May 2015 322 pages 1st Edition
eBook
R$80 R$218.99
Paperback
R$272.99
Subscription
Free Trial
Renews at R$50p/m
eBook
R$80 R$218.99
Paperback
R$272.99
Subscription
Free Trial
Renews at R$50p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781784398378
Vendor :
Microsoft
Languages :
Concepts :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

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

Packt Subscriptions

See our plans and pricing
Modal Close icon
R$50 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
R$500 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 R$25 each
Feature tick icon Exclusive print discounts
R$800 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 R$25 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total R$ 729.97
Learning Microsoft Azure
R$272.99
Microsoft Azure Security
R$183.99
Building Web Services with Windows Azure (new)
R$272.99
Total R$ 729.97 Stars icon

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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.