public class UsLocationRecord { public int Id { get; set; } public string ZipCode { get; set; }...
-
Upload
dominick-cole -
Category
Documents
-
view
248 -
download
0
Transcript of public class UsLocationRecord { public int Id { get; set; } public string ZipCode { get; set; }...
ASP.NET Web APIWeb Services for Web Sites and Modern & Mobile AppsBrady GasterWindows Azure Technical Evangelist
DEV-B360
IntroductionsIt always helps to know who you’re dealing with, so here’s a little background on me.
@bradygaster
1 Wife (Gina)
2 Chihuahuas (Lola & Nico)
Windows Azure Technical Evangelist
bradygaster.com
2 Sons (Gabe & Lucas)
Originally from NC (hence the funny accent)
2 Guitars (Fender, Gretsch)
AgendaWhat are we going to talk about today?
Web API Test Clients
Modern Apps with Windows 8
Mobile Apps with Xamarin
Example Scenario
Portable Class Libraries
Mobile Apps with Windows Phone 8
Authentication with Web APICross Origin Resource Sharing
Example ScenarioHere’s a look at the database we’re going to expose using a Web API
Example ScenarioEntity Framework Class View Model Classpublic class UsLocationRecord{ public int Id { get; set; } public string ZipCode { get; set; } public string City { get; set; } public string State { get; set; } public DbGeography Location { get; set; }}
public class UsLocation{ public int Id { get; set; } public string ZipCode { get; set; } public string City { get; set; } public string State { get; set; } public double Latitude { get; set; } public double Longitude { get; set; }}
This doesn’t serialize too well, so we need a View Model
There. That’s better.
Demo
Running the Sample API
Web API Test ClientNuGet Package
NuGet Package Link: http://aka.ms/Kuqhny
Any browser
Templates are .CSHTML files
Introduction and how-to:http://aka.ms/webapitestclientintro
PostmanChrome Plugin
http://www.getpostman.com/
Demo
Setting up and using the Web API Test Client
.NET is supported by many platformsMany tricks have been employed to write reusable components that work on all of them
Code Files for “reusable” classes
Models.SilverlightModels.Phone Models.WindowsModels
UX.SilverlightUX.Phone UX.WindowsUX.Web
ApiClient.SilverlightApiClient.Phone ApiClient.WindowsApiClient.Web
“reused code” isn’t the same as“reusable code”
Portable Class LibrariesCommon code that can be shared across all the .NET environments
Code Files for reusable classes
UX.SilverlightUX.Phone UX.WindowsUX.Web
Common PCL
Demo
Writing a Portable Class Library to Provide a client API
Client Platform
Modern and Mobile ClientsWindows 8 Store Apps and Windows Phone 8 Apps can use the PCL
Windows 8Store App
Windows Phone 8 App
PCL HTTP
Server Platform
Web API Controller
Demo
Using Web API in Modern Apps with Windows 8
Demo
Using Web API in Mobile Apps with Windows Phone 8
XamarinC# everywhere, even on iOS and Android
Demo
Communicating with a Web API using a C# Android Client
Sharing Data Across APIs Should be EasyMy web site has an API, your web site has an API, let’s make a mash-up!
foo.com bar.comHTML
AJAX
HTTP Request
AJAX(from pagehosted onfoo.com)
?JSON
CORS
Cross Origin Resource SharingOnce CORS is enabled, cross-domain communication via AJAX/HTTP/JavaScript is possible
foo.com bar.comHTML
AJAX
JSON
AJAX
JSON
Demo
Enabling Cross Origin Resource Sharing
Web API & AuthenticationThe framework & tooling release will make API simple & allow for federationWeb API app configured to use OAuth Bearer TokensClient app asks Web API what OAuth providers it supportsUser selects provider and is redirected to loginUpon login, user redirected back to API site with credential stringCredential string is parsed into a claim, then an identityUserInfo is passed back to client where it is persistedUserInfo’s access token is attached to each API request as a Bearer Token HeaderAPI performs authorization using the Bearer Token Header
Demo
Walking through a Multi-client Authentication Process
Related contentBreakout Sessions (session codes and titles)Hands-on Labs (session codes and titles)Product Demo Stations (demo station title and location)Related Certification ExamFind Me Later At...
Track resourcesGeneric Client REST Wrapperhttps://gist.github.com/bradygaster/5682105Web API Test Client How-tohttp://aka.ms/webapitestclientintroASP.NET on CodePlexhttp://aspnetwebstack.codeplex.com/Channel Web Camps TV EpisodesKatana - http://aka.ms/C7xunhCORS - http://aka.ms/Q3uthfOData - http://aka.ms/Txrdhu, http://aka.ms/V4n6cvYao’s Web API Tour - http://aka.ms/G24zpi
msdnResources for Developers
http://microsoft.com/msdn
LearningMicrosoft Certification & Training Resources
www.microsoft.com/learning
TechNet
Resources
Sessions on Demandhttp://channel9.msdn.com/Events/TechEd
Resources for IT Professionalshttp://microsoft.com/technet
Complete an evaluation on CommNet and enter to win!
MS tag
Scan the Tagto evaluate this session now on myTechEd Mobile
© 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.