2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

37
INT07 WCF, JSON and AJAX for performance and manageability Daniel Fisher [email protected] e Software Architect | CTO devocach® Michael Willers [email protected] e Software Architect | CTO devocach®

Transcript of 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

Page 1: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

INT07WCF, JSON and AJAX for performance and manageabilityDaniel [email protected] Architect | CTO devocach®

Michael [email protected]

Software Architect | CTO devocach®

Page 2: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

www.devcoach.com Experts each with 10+ years experience

Development Architecture Consulting & Coaching

Community activists Annual Software Developer Community Event

Deep knowledge and skills on Service Orientation & Agile Methods Web & Data access Security & Deployment

Real Projects – Not just cool demos!

Page 3: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

AgendaPerformanceManagabilityPitfallsSummary

Page 4: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

Performance

Page 5: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

What is PerformanceDevelopment

Beiing Agile

TechnicalDesign enabling a fast execution of functionalityCode written to be executed with low memory and cpu utilization

Non-TechnicalUser ExperienceResponsiveness of an application

Page 6: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

What makes bad performance?

Un-necessary thingsMultiple rendering of UIMultiple transfer of data over the wire

Don‘t repeat yourself

Page 7: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

HTTP vs. AJAXHTTP

Ajax

Page 8: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

The Ajax technique soupXHTML (or HTML) and CSSECMAScript/JavaScriptXMLHttpRequest object/IFrame objectXML, JSON

Ajax is not a technology in itself, but a term that refers to the use of a group of technologies.

Page 9: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

Ajax HistoryMost of the technologies that enable Ajax started with Microsoft's initiatives in developing Remote Scripting in 1998.Microsoft created the XMLHttpRequest object in IE 5 and first used it in Outlook Web Access supplied with Exchange 2000. 2003 not long before Microsoft introduced Callbacks in ASP.NET.“AJAX” was first used by Jesse James Garrett in February 2005 as a shorthand term to the suite of technologies as a proposal to a client.

Page 10: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

AJAX w/o ASP.NET Pt. 1

var request = new Request(); function _getXmlHttp(){ /*@cc_on @*/ /*@if (@_jscript_version >= 5)

var progids=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] or (i in progids) {

try { return new ActiveXObject(progids[i]) }catch (e) {}

} @end @*/ try { return new XMLHttpRequest();} catch (e2) {return null; }}

function Request() { this.Get = Request_get; this._get = _getXmlHttp(); if (this._get == null) return;}

...

Page 11: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

AJAX w/o ASP.NET Pt. 2

...ReadyState = { Uninitialized: 0, Loading: 1, Loaded:2, Active:3, Completed: 4 }HttpStatus = { OK: 200, NotFound: 404 }

function Request_get(url, f_change, method) {if (!this._get) return;if (method == null) method="GET";if (this._get.readyState != ReadyState.Uninitialized)

this._get.abort() this._get.open(method, url, true);if (f_change != null)

var _get = this._get;this._get.onreadystatechange = function(){ f_change(_get);}

this._get.send(null);}

Page 12: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

AJAX w/o ASP.NET Pt. 3

...function ajaxInnerHTML(method, args, elmId){ request.Get( url + "?m=" + escape(method) + "&p=" + escape(args), function(result) { if (result.readyState!=ReadyState.Complete)

return;

if (result.status==HttpStatus.OK && result.responseText != "")

{ elm = document.getElementById(elmId); if(elm)

{ var response = result.responseText;

elm.innerHTML = response; } }

});}

Page 13: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

AJAX w/o ASP.NET - SummaryWorks just with „ugly hacks“?

Or just in one browser (version)Javascript is not type safe

Code like in the 90‘s...Welcome to WEB 0.5?

Page 14: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

What is ASP.NET AJAX?An framework for building rich, interactive Web experiences and browser-applications

Microsoft AJAX LibraryCross-browser compatible client script framework

ASP.NET AJAX ExtensionsServer controls enabling AJAX in ASP.NET applications

ASP.NET AJAX FuturesFeatures of future AJAX Extension releases (Betas)

ASP.NET AJAX Control ToolkitRich set of server controls and client script functionality

Page 15: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

AJAX Topology

Client Server

HTML, XML, JavaScript, CSS

ASP.NET

Ajax ExtensionsApp Services BridgeWeb Services Bridge

AJAX Enabled ControlsControl ToolkitAjax Control Toolkit

Ajax Control Extender

Microsoft Ajax LibraryScript Core

Base Class LibraryComponent Model

UI Framework

Page 16: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

Microsoft AJAX Library

Architecture

IE, Firefox, Safari, …)

Browser Compatibility

Asynchronous Communications

Script Core Library

Base Class Library

XHTML/CSS

JSON Serializer WSProxiesXML-HTTP

Page 17: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

AJAX with ASP.NET

var request = new Sys.Net.WebRequest();request.set_url('Default.aspx');request.add_completed( function(response, args){ if (response.get_statusCode() == 200) { window.alert(response.get_responseData()); } });request.invoke();

Page 18: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

ASP.NET AJAX Web ServicesASP.NET AJAX clients can consume Web services

ASMXWCF

ASMX model extended to support JSON endpointsServer framework includes JSON serializer

Microsoft.Web.Script.Serialization.JavaScriptConverter

Also includes ASMX front-ends for ASP.NET 2.0 profile service and authentication service

Page 19: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

XML

<Person><id>1234</id><FirstName>John</FirstName><LastName>Doe</LastName><Address>21 Jump ST</Address><City>Springfield</City><State>GA</State><Zip>55555</Zip>

</Person>

Page 20: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

JSON

{"Person":

[{

"id":"1234","FirstName":"John","LastName":"Doe","Address":"21 Jump ST","City":"Springfield","State":"GA","Zip":"55555"

}]

}

Page 21: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

AJAX & Web Services

Create a service referenceView the generated ProxyCall the web service

Demo

Page 22: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

AJAX & WCF Web ServicesBinding for AJAX

webHttpBinding (Serializer for JSON)HTTP Verb Attributes & URI-Template

Enable REST-APIsFactory-attribute

Enables configuration-less servicesConfiguration

Support webHttpBinding as additional endpoint

Page 23: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

Managability

Page 24: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

What is managabilityA code base that is easy to maintain, extend and localize.Code that tells you where to find the error if one appears.

A Development Environment that supports the developer

Syntax HighlightingIntellisenseCompile Time Errors

Page 25: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

Less Code = Less Bugs

// JavaScript w/o ASP.NETvar obj = document.getElementById( ‘id_of_object‘);

// JavaScript with ASP.NETvar obj = $Get(‘id_of_object‘);

Page 26: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

Less Code

Case Study: vision4health

Demo

Page 27: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

AJAX Library Debugging Objects

Sys.Debug.assert(condition, message, displayCaller)

Checks for a condition - if the condition is false, displays a message and prompts to break into the debugger.

Sys.Debug.clearTrace() Clears all trace messages from the TraceConsoletextarea element.

Sys.Debug.traceDump(object, name) Dumps an object to the debugger console and to the TraceConsoletextarea element, if available.

Sys.Debug.fail(message) Displays a message in the debugger's output window and breaks into the debugger.

Sys.Debug.trace(text) Appends a text line to the debugger console and to the TraceConsoletextarea element, if available.

Page 28: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

Debugger API internals

function Sys$_Debug$_appendConsole(text) { // VS script debugger output window. if ((typeof(Debug) !== 'undefined') && Debug.writeln) { Debug.writeln(text); } // Firebug and Safari console. if (window.console && window.console.log) { window.console.log(text); } // Opera console. if (window.opera) { window.opera.postError(text); } // WebDevHelper console. if (window.debugService) { window.debugService.trace(text); }

Page 29: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

Debug & Trace

Case Study: AUTOonline

Demo

Page 30: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

PitfallsBrowser integration

No HistoryNo Bookmarks

Response-time concernsSearch engine optimizationJavaScript reliability and compatibilitySource code fully exposed to clientAnother language, another skill setHarder to debugIncreased web requests

JSON != Performance Language Layer InterOp

Page 31: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

SummaryMicrosoft ASP.NET AJAX enables easy develpment of „Application“ that live in the Web 2.0AJAX still means server round-trips, so design carefullyIt‘s a cool tool

Page 32: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

Thank you!

Page 33: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

Outros RecursosPara Profissionais de TI

Beneficie de 40% de desconto.

Faça a sua Subscrição em

www.gettechnetplus.com e utilize o

promocode TLNW08

Software em versão completa para avaliação2 incidentes de suporte gratuito profissionalAcesso antecipado às versões betasoftware exclusivo: Capacity Planneractualizações de segurança e service packsformação gratuita ….e muito mais.

www.microsoft.com/portugal/technet/subscricoes

Page 34: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

Outros RecursosPara Programadores

Software em versão completa para avaliaçãoSuporte técnico 24x7 para incidentesAcesso antecipado às versões betaMicrosoft OfficeSoftware Assuranceformação gratuita ….e muito mais.

www.microsoft.com/portugal/msdn/subscricoes

Page 35: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

Outros RecursosCertificações

www.microsoft.com/learning

Até 30 Junho 08, beneficie de uma

segunda tentativa para fazer o seu

exame de certificação!

Page 36: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

Questionário de Avaliação Passatempo!

Complete o questionário de avaliação e devolva-o no balcão da recepção…

…e habilite-se a ganhar 1 percurso de certificação por dia! Oferecido por:

…e habilite-se a ganhar 1 percurso de certificação MCTS por dia! Oferecido por:

…e habilite-se a ganhar 1 curso e exame por dia! Oferecido por:

Session Code Session Name

Page 37: 2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability

© 2008 Microsoft Corporation. Todos os direitos reservados.Esta apresentação destina-se apenas a fins informativos.A MICROSOFT NÃO FAZ GARANTIAS, EXPRESSAS OU IMPLÍCITAS NESTA APRESENTAÇÃO.