Date post: | 03-Dec-2014 |
Category: |
Documents |
Upload: | sampetruda |
View: | 1,428 times |
Download: | 0 times |
ASP.NET AJAX with Web Services
Noah SubrinAtlanta MS ProsCutting EdgeVB .Net Study GroupNovember 5, 2007
Speaker Biography
Technical Lead – SRA International MCSD and MCSD .Net Participates in developer community
events in the Southeast Published several articles on
www.sswug.org
What we will discuss tonight
Brief ASP .Net AJAX 1.0 overview AJAX Programming models Focus on Remote Services Web Services Page Methods Built in API’s
Traditional Web Apps
Web was originally designed for static pages
Today’s web is much more interactive.
Client issues a request, the server returns HTML markup, and the entire page is refreshed
Everything is done on the web server
AJAX-Enabled Applications AJAX apps use a client side framework
to make out of band calls to the server AJAX server side framework returns
data to the customer that is primarily in the form of JSON but may be XML or other formats such as RSS, CSV
Reduces bandwidth required and UI’s are able to be redrawn using partial rendering
More code is executed on the browser
So What is ASP .Net 2.0 AJAX?
Server side ASP 2.0 AJAX extensions that are installed in global assembly cache (GAC)
Client side JavaScript libraries that can be used stand alone
Visual Studio 2005 or Visual Web Developer are not necessary to use server side components (but they provide templates)
AJAX Programming Models
Partial Page Rendering Script Services Local web services Page Methods How to call external web services Authentication services Profile Web services
Characteristics of AJAX services
REST services (Representational State Transfer)
Each URL represents the state of an object retrieved using an HTTP verb (GET, POST, PUT)
Tied to the platform and domain where they are hosted
Not SOA in truest sense Who uses REST ? Amazon, Yahoo
and many others
REST Web Services
Predates the WS* specs Typically easier to read than SOAP New operation can be exposed
without updating web reference REST relies on HTTP verbs and
URL’s to express the operation Not a standard (like SOAP) or a
protocol (like HTTP) Each operation has a distinct URL
SOAP Web Services
SOAP services are an XML based protocol SOAP services need an envelope, message, header, and body
WSDL to describes the web service API
XML Schema describes the call Uses a single URL Can support WS* specs
AJAX Web Services Demos
Expose the web services to clients Calling web services from the client Fire and Forget Returns a Value Takes Parameters Handles an Error Lengthy Operation User Context and method Names Complex Types
Why only Local Services?
Security implications of cross site calls
SOAP is harder to manage from client side JavaScript
No XML parser is needed Support for JSON serialization which
uses name-value pairs
What about WCF Services?
In ASP .Net AJAX 1.0 we are currently unable to call WCF services
Support for WCF services calls from AJAX in Orcas will presumably be enhanced
Page Methods
Provide ability for client script to call a static method in an ASP .Net page as if it were a web service.
Scoped within a page -cannot be called from a different page other than where they are defined
Decorated with WebMethod attribute
More on Page Methods
All types will be JSON serialized Not enabled by default, to enable,
we set the ScriptManager property EnablePageMethods=true
The page acts as a web service
PageMethods Demo
Writing to Session object from a PageMethod
PageMethods vs AJAX Web Services
From PageMethods we can access Session state, ASP .Net Cache, and User objects
For PageMethods we don’t have to create an .asmx web service
Local Web services are callable from every page
Web services are callable by SOAP based clients
For both - don’t include any critical business logic (replay attacks)
Calling external web services
Not included in ASP .Net AJAX Extensions 1.0
New file type .asbx, which is an xml file It contains info on how to connect to a
remote web service This is a Futures technology but it is
possible to build manually using WebMethod or PageMethod
Client calls its own server – local server calls a remote server
Application Services
Forms Authentication Profile Information
Forms Authentication
We can use the MS AJAX library authentication service to verify credentials stored as part of the ASP .Net membership application service
Server configuration is in web.config Server issues a ticket Client browser needs cookies
enabled
Forms Authentication Demo
Restrict Directory Access JavaScript Functions Web.config settings Membership provider
Profiles Web Services
The profile service enables you to use the ASP.NET profile application service from client side JavaScript
Must enable the Profile Service in the web.config
By default, no profile properties are available. For each profile property that you want to make available in a client application, add the property name to the readAccessProperties attribute of the <profileService> element.
Profile Services Demo
Adding custom properties to a .Net 2.0 Provider
Summary
We can create and expose local web services to client side JavaScript
We can use local web services or PageMethods
We used JSON serialization We leveraged callback functions to
update the pages We can call ASP.Net 2.0
Authentication and Profile services from client side JavaScript
Additional Resources www.asp.net/ajax SOAP Specification
http:www.w3.org/tr/soap) REST Specification
http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm
Introducing Microsoft ASP .Net AJAX by Dino Esposito
Professional ASP .Net 2.0 AJAX by Matt Gibbs and Dan Wahlin
Contact Info
Email address: support @federalsystems.net
o Blog: blogs.federalsystems.net