Building Web Services with Windows Azure (new) - Alex Belotserkovskiy - E-Book

Building Web Services with Windows Azure (new) E-Book

Alex Belotserkovskiy

0,0
35,99 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

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.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 325

Veröffentlichungsjahr: 2015

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Building Web Services with Microsoft Azure
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
Introduction
Getting to know HTTP
An HTTP request/response
HTTP methods
HTTP status codes
Other HTTP goodies
Header field definitions
Content negotiation
HTTP 2.0
HTTP and .NET
The rise of REST
The REST style of services
Web API and Microsoft Azure
Summary
1. Getting Started with the ASP.NET Web API
The ASP.NET Web API framework
Background
Building blocks
Design principles behind the ASP.NET Web API
Application scenarios
Behind the scenes with the ASP.NET Web API
Anatomy of the API of ASP.NET Web API
DelegatingHandler
HttpRequestMessage
HttpResponseMessage
ApiController
Other important types
Message lifecycle
Host listener
Routing and dispatching
Controller processing
Creating our first ASP.NET Web API
Prerequisites
Creating the ASP.NET Web API project
Defininig an ASP.NET data model
Defining an ASP.NET Web API controller
Testing the Web API
Testing in a browser
Testing with HttpClient
Committing changes to Git
Deploying the ASP.NET Web API using Azure Websites
Deploying to Azure Websites
Continuous Deployment using Azure Websites
Summary
2. Extending the ASP.NET Web API
Attribute routing
Custom route discovery using IDirectRouteProvider
Content negotiation
Customizing content negotiation
Customizing media formatters
Securing the ASP.NET Web API
Authentication and Authorization filters
Creating an Azure AD directory
Enabling authentication for the Web API project
Configuring the Web API in Azure AD
Enabling Authorization for the controller
Testing our secure Web API
Creating the test client
Configuring the test client in Azure AD
Updating the test client
Hosting
Summary
3. API Management
Azure API Management
Managing a Web API
Creating an API Management service
Configuring the API Management service
Creating API operations
Adding an operation
Adding an authorization server
Configuring an API with an authorization server
Adding a product
Consuming the Web API
Summary
4. Developing a Web API for Mobile Apps
Azure Mobile Services
Features of Azure Mobile Services
Core services
The API of Azure Mobile Services
TableController
ApiServices
EntityData
Domain Manager
Creating a Web API using Mobile Services
Creating the project
Defining the data model
Record
Doctor
Creating the controller
Testing the mobile service
Testing in a browser
Testing using a Windows 8.1 application
Deploying to Azure Mobile Services
Leftovers
Summary
5. Connecting Applications with Microsoft Azure Service Bus
Azure Service Bus
What is Azure Service Bus?
Patterns
Publish/Subscribe
Messaging bridge
Dead Letter Channel and Invalid Message Channel
Content Based Router and Recipient List
Splitter and Aggregator
Resequencer
The BrokeredMessage object
How do you create elements of the Service Bus?
Creating a Service Bus Queue
Interacting with the Queue
Sending a message to the Queue
Receiving a message from the Queue
Receiving different message types from a Queue
Creating a Service Bus Topic
Creating a rule with Visual Studio's Server Explorer
Creating a rule with code
Interacting with the Topic
Sending a message to a Topic
Receiving a message from a Topic
Creating an event hub
Sending data to an event hub
Reading data from an event hub
Service Bus Security
Summary
6. Creating Hybrid Services
Service Bus Relay Service
Bindings
Creating Relay Service in Azure
Creating the WCF service
Creating the client
BizTalk Hybrid Connect
Hybrid Connect security
Summary
7. Data Services in the Cloud – an Overview of ADO.NET and Entity Framework
Key layers of distributed applications
The data layer
The business logic layer
The server layer
The user interface layer
Data and data access technologies
ADO.NET and ADO.NET Entity Framework
Creating a data source for a Web API application
Creating a Microsoft Azure SQL database
Using the Microsoft Azure SQL database management portal
Populating a Microsoft Azure SQL database table with test data
Adding a Microsoft Azure SQL database to the project
Creating an Entity Data Model
Testing the Web API with Entity Framework and Microsoft Azure SQL database
Testing an insert operation
Summary
8. Data Services in the Cloud – Microsoft Azure Storage
Microsoft Azure Storage
The Microsoft Azure Storage Blobs service
Security
The Microsoft Azure Storage Queues service
The Microsoft Azure Storage Tables service
Tables and entities
Using Microsoft Azure Storage in the Web API application
Creating storage accounts
Adding storage support to the Web API application
Viewing data from the table
Summary
9. Data Services in the Cloud – NoSQL in Microsoft Azure
Understanding NoSQL
An overview of Microsoft Azure NoSQL technologies
Microsoft DocumentDB
The Microsoft DocumentDB object model
DocumentDB in a Web API application
Creating the DocumentDB database account
Using DocumentDB in the Web API application
Testing the Web API with the DocumentDB database account
Microsoft Azure Marketplace
MongoLab MongoDB on Microsoft Azure
Creating a MongoLab MongoDB subscription
Summary
Index

Building Web Services with Microsoft Azure

Building Web Services with Microsoft Azure

Copyright © 2015 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: May 2015

Production reference: 1220515

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-78439-837-8

www.packtpub.com

Credits

Authors

Alex Belotserkovskiy

Stephen Kaufman

Nikhil Sachdeva

Reviewers

Harsh

Alon Fliess

Harshwardhan Joshi

Commissioning Editor

Kunal Parikh

Acquisition Editors

James Jones

Greg Wild

Content Development Editor

Akashdeep Kundu

Technical Editor

Mrunmayee Patil

Copy Editors

Pranjali Chury

Brandt D'Mello

Project Coordinator

Milton Dsouza

Proofreaders

Stephen Copestake

Safis Editing

Indexer

Monica Ajmera Mehta

Production Coordinator

Arvindkumar Gupta

Cover Work

Arvindkumar Gupta

About the Authors

Alex Belotserkovskiy is a technical evangelist for Microsoft Russia and lives in Moscow. He specializes in cloud, Internet of Things, and high performance computing topics. Alex is actively engaged in both local and international speaking activities, and works with top customers and partners to provide professional technical and technological support for their cloud projects.

Alex was the first Russian Windows Azure Most Valuable Professional, in 2012, and is a Microsoft certified developer and enterprise administrator. He is an experienced Microsoft technologies instructor.

I would like to thank my fiancee, Olga Vilkhivskaya, for putting up with my late night writing sessions and ideas. I would also like to express deep gratitude to Andrey Ivashentsev, Technical Evangelism Unit Lead for Microsoft Russia, without whose efforts this book would not have happened. Alexey Bokov, Technical Evangelist in Microsoft, has my gratitude for continuing to give me valuable experience and advice on how to do things in a better manner.

Stephen Kaufman works for Microsoft as a solution architect in the Americas Office of the CTO and is the lead architect for the US Azure PaaS Center of Expertise (CoE).

He is a public speaker and has appeared at a variety of industry conferences nationally and internationally at events, such as TechEd North America, TechEd EMEA, Microsoft SOA and BPM conference, as well as many internal Microsoft conferences over the years discussing application development, integration, and cloud computing, as well as a variety of other related topics.

Stephen is also a published author with two books—Pro BizTalk 2009 (http://www.apress.com/book/view/1430219815) and Pro Windows Server AppFabric (http://www.apress.com/book/view/1430228172), both by Apress Publishing—as well as a number of whitepapers and other published content, including a blog at http://blogs.msdn.com/skaufman.

In addition, he is a board certified architect (CITA-P-IASA Global) and continues to work mentoring and sitting on architecture certification review boards.

Lastly, Stephen was a contributing author for the Azure Architecture Certification Exam 70-534, Architecting Azure Solutions.

Nikhil Sachdeva is a senior consultant at Microsoft. He has over 11 years of experience in architecting and implementing scalable web applications and services using Microsoft technologies. He has been involved with Microsoft Azure since its early days and currently works as a subject matter expert in building custom Platform as a Service (PaaS) solutions on the Azure platform. He has a passion for writing and is a contributing writer for Introducing Windows Azure for IT Professionals, Microsoft Press, and has contributed to several other Microsoft articles and blogs on Microsoft Azure and related technologies. His recent passion is building highly scalable and available solutions for the Internet of Things (IoT) and frequently rants his experiences at http://connectedstuff.net.

I would like to thank my beautiful wife, Pratibha, for encouraging me to pursue my passion for writing and supporting me throughout the process. Thanks for being my support system, my buddy, my critic, and for giving me the best gift of life, our newborn son, Ayansh. A special thanks to the team at Packt Publishing for their continuous support and patience.

About the Reviewers

Harsh works as a software engineer for Microsoft. He has worked on quite a few things and he feels that it still hasn't been enough for his exploration and he should keep trying new technologies and keep learning.

Besides his interest in cloud computing (read Azure) and programming in general, he likes reading and fiddling with CTF questions and ciphers. He started the HackCon (Build the Shield) event in Microsoft, which is Microsoft's version of Capture the Flag events. He is also a moody blogger and tries to keep his portfolio up to date. You can find him at http://hars.in.

I would like to thank my friends and colleagues from whom I learn every day.

Alon Fliess is the chief architect and founder of CodeValue. He got his BSc degree in electrical and computer engineering from Technion, the Israel Institute of Technology. He is also recognized as a Microsoft Regional Director (MRD). He is an expert in many technologies, be it Windows internals, C++ Windows programming (Win32/WinRT), .NET with C#, Windows Azure Cloud Computing, or Internet of Things (hardware and software).

Alon spends his time doing many interesting tasks such as software architecting, designing, mentoring, and programming. He is the author and technical reviewer of several computing books. Alon is an active member of several Patterns & Practices councils, among them is project Hilo—a Windows Store Application in C++/CX and XAML.

He is one of the experts in the Microsoft Israel community. He helps Microsoft clients in many technological aspects. He gives lectures at Israeli and international conferences, such as NDC, CVCon, TechEd, and more.

To Deepti Thore, who gave me the chance to review this book, and to Milton Dsouza, who had the patience to wait for me to complete the review—thank you both.

To my beloved wife, Liat, and my three children, Yarden, Saar, and Adva, thank you for all your understanding and support.

Harshwardhan Joshi lives and works in Pune and loves spending time with his wife, and pet cat named "Hulk". He calls himself "a Cloud engineer who writes APIs for a living". He has been passionately working on several Microsoft technologies from .NET Framework, Microsoft Silverlight, WF, and WCF to Microsoft Azure for the last 7 years and has worked on creating several exciting products. He has been working on Microsoft Azure since its inception. He currently works with RapidCircle as a Cloud Consultant. In his previous stint with Icertis, he was one of the core members responsible for building highly scalable, always available, and high performance APIs on Microsoft Azure.

You can meet him at events organized by the Pune User Group, a group for avid developers in Microsoft Technologies in Pune. He stays updated on the latest cars and engines hitting the market. He is a regular contributor to the Team-BHP forum. He can also be found on Twitter at @hjoshi.

Thanks to Packt Publishing for this amazing opportunity to review this book on Microsoft Azure. I hope you all enjoy reading this book as much as I enjoyed working on it. I would also like to thank my family and friends for being extremely supportive.

www.PacktPub.com

Support files, eBooks, discount offers, and more

For support files and downloads related to your book, please visit www.PacktPub.com.

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

https://www2.packtpub.com/books/subscription/packtlib

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.

Why subscribe?

Fully searchable across every book published by PacktCopy and paste, print, and bookmark contentOn demand and accessible via a web browser

Free access for Packt account holders

If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.

Preface

With multiple cloud platforms out there, it is easy to get confused when making a technology decision for your projects. This gets further complicated with the plethora of development tools and frameworks available today. Microsoft Azure simplifies this problem by providing a scalable and manageable platform for customers to easily deploy, monitor, and troubleshoot their cloud-based applications. Its seamless integration with new and existing Microsoft tools and inherent support for open source software makes it an obvious choice for building cloud-based applications and services.

Whether you are new to Microsoft Azure cloud development or you have been creating cloud applications, there will be something new for you in this book. We will cover the full application development architecture and cover all tiers of an application. We will also cover a number of patterns that you will encounter, from solutions that are completely hosted in the cloud to hybrid solutions where applications are split between the cloud and on-premises networks.

What this book covers

Chapter 1, Getting Started with the ASP.NET Web API, introduces the ASP.NET Web API framework and provides an overview of its application and internals. It will guide you through the stages of creating a Web API and deploying it in Microsoft Azure.

Chapter 2, Extending the ASP.NET Web API, discusses various extensibility and customization options available in the ASP.NET Web API framework. It guides the reader through various extension points, such as custom routing, message formatters, content negotiation, and securing a Web API. It also discusses various hosting options for deploying Web APIs.

Chapter 3, API Management, provides a set of tools that assist API developers in managing and monitoring Web APIs. We will discuss various options of publishing, marketing, monitoring, and managing a Web API using API management.

Chapter 4, Developing a Web API for Mobile Apps, provides an overview of Mobile Services and walks through a scenario of creating a Web API using Mobile Services. Mobile Services provides an easy-to-use environment to rapidly build cross-platform apps for Windows, iOS, Android, and other platforms. Its rich built-in capabilities for managing backend login, data, authentication, and notifications makes it a compelling option for developing mobile applications.

Chapter 5, Connecting Applications with Microsoft Azure Service Bus, discusses Windows Azure Service Bus, which allows for related and brokered messaging using a range of different features (such as Topics and Queues).

Chapter 6, Creating Hybrid Services, demonstrates how to create Hybrid Services to connect on-premises Large Object (LOB) / database to cloud-based applications. Essentially, this chapter builds on the previous chapter, demonstrating how you can use the elements of the Service Bus to create Hybrid applications. It will also demonstrate how to effectively maintain these applications.

Chapter 7, Data Services in the Cloud – an Overview of ADO.NET and Entity Framework, explores how to create data services in the cloud using Entity Framework and ADO.NET.

Chapter 8, Data Services in the Cloud – Microsoft Azure Storage, explores how you can use cloud-based Azure Storage technologies.

Chapter 9, Data Services in the Cloud – NoSQL in Microsoft Azure, explores how to use DocumentDB, a fully managed, highly scalable NoSQL data management service based on Azure, as well as ways to start using other open source Azure options such as MongoDB.

What you need for this book

The hardware requirements are as follows:

1.6 GHz or faster processor1 GB of RAM (1.5 GB if running on a virtual machine)10 GB (NTFS) of available hard disk space5400 RPM hard driveDirectX 9 capable video card running at 1024 x 768 or higher display resolution

The software requirements and their download or purchase sources are mentioned in the following list:

Windows 8.1 or greater at http://www.microsoftstore.com/store/msusa/en_US/pdp/Windows-8.1/productID.288401200?tduid=e43fc220a3cc8877116cc4a027cb6456You can also use your MSDN license to download a copyVisual Studio 2013 Community Edition or greater at https://www.visualstudio.com/en-us/products/visual-studio-community-vs.aspx

Note

Note that the samples have only been tested on Visual Studio 2013 and not on Visual Studio 2015 preview.

Azure SDK 2.5 at https://www.microsoft.com/en-us/download/details.aspx?id=44938Entity Framework at https://www.nuget.org/packages/EntityFramework/6.1.1Other helpful tools:
Resharper: https://www.jetbrains.com/resharper/Chrome Postman: https://chrome.google.com/webstore/detail/postman-rest-client-packa/fhbjgbiflinjbdggehcddcbncdddomop?hl=enFiddler: http://www.telerik.com/download/fiddler/fiddler4Azure Storage Explorer: https://azurestorageexplorer.codeplex.com/Service Bus Explorer: https://code.msdn.microsoft.com/windowsazure/service-bus-explorer-f2abca5a

Who this book is for

If you are a developer or an architect who wants to develop end-to-end RESTful applications in the cloud, then this book is for you. You will need professional knowledge of C# to work through the projects in this book.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail <[email protected]>, and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at <[email protected]> with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at <[email protected]>, and we will do our best to address the problem.

HTTP 2.0

HTTP 2.0 is the next planned version of the HTTP protocol specification and is an attempt to optimize the usage of network resources and reduce latency through header compressions and pooling multiple connections over the same channels. The initiative is spearheaded by Google and Mozilla research teams and as of today, is in a working draft state. The good news is that HTTP 2.0 is going to retain all the goodness of HTTP 1.1 while making it more performant over the wire through efficient processing of messages. Since HTTP 2.0 is still in the making, we will refrain from using it for the scope of this book. However, if you are enthusiastic to know more about HTTP 2.0, you can take a look at the current draft of the specification at http://http2.github.io/http2-spec/.

For the scope of this book, HTTP always refers to HTTP 1.1 specification of the protocol.

HTTP and .NET

Starting from .NET 4.5, a new namespace and assembly was added as part of the framework, System.Net.Http. The resemblance of the types in this namespace may look behaviorally similar to those defined in ASP.NET System.Web.Http namespace; however, the addition of this namespace marks a big difference in the development of HTTP services.

Firstly, it enables unified communication over HTTP by providing a set of abstract types. These types allow any .NET application to access HTTP services in a consistent way, for example, now both the client and server can use the same HTTP programming model for better development experience. Secondly, it has been written to target modern HTTP apps such as Web API and mobile development, this signifies the investment of Microsoft in making HTTP services a first-class citizen.

Some of the key types defined in this namespace are:

Type

Description

HttpClient

This enables primitive operations for sending HTTP requests and receiving HTTP responses from a resource identified by a URI.

HttpRequestMessage

This represents the HTTP request message from a client.

HttpResponseMessage

This represents the HTTP response message received from an HTTP request.

HttpContent

This is a base class that represents an HTTP entity body and any content headers.

HttpMessageHandler

This is the base type for all message handlers and this will be used to define all message handlers. Message handlers may be used to create server-side or client-side handlers.

The server-side handler works with the hosted model chain and handles incoming client requests (HttpServer and HttpSelfHostServer). It determines the correct route for the request (HttpRoutingDispatcher) and dispatches the request to the controller (HttpControllerDispatcher).

The HttpClient type uses client-side message handlers to process requests. The default handler HttpClientHandler is responsible to send the request and get the response from the server.

We may, of course, hook our custom controllers in the pipelines, for example, to validate, modify, or log the requests.

Note

For a complete list of all types available in the System.Net.Http namespace, please visit http://msdn.microsoft.com/en-us/library/system.net.http(v=vs.110).aspx.

We will see in the later sections that the ASP.NET Web API also leverages some of the System.Net.Http types for communication over HTTP.

The rise of REST

When talking about Web APIs, it is imperative to mention the REST framework. Over the years, REST has proven to be a much simplified and efficient web service architecture style as compared to other architectures like RPC-based SOAP. The key reason for this popularity is because of its modern web design patterns and utilization of HTTP transport layer features to the fullest. REST has enabled many modern-world scenarios such as Mobile apps and Internet of Things (IoT), which would be challenging with protocols like SOAP because of its rigid schema-based WSDL structure and bulky XML standards.

Note

A good comparison of REST and SOAP protocols can be found at http://blog.smartbear.com/apis/understanding-soap-and-rest-basics/.

The REST style of services

REST stands for Representational State Transfer and perhaps the most important thing to realize about REST is that it is an architecture style and not a standard (like SOAP). What do we mean by this?