Microsoft PowerPoint - PDF 2
Document Sample


ASL203: Building RIAs with AJAX,
Silverlight and WCF
Michele Leroux Bustamante
Chief Architect, IDesign
Microsoft Regional Director
About Michele
Leroux Bustamante
L B t t
• Chief Architect, IDesign: www.idesign.net
• Microsoft Regional Director
• MVP – Connected Systems
y
• Author: Learning WCF (O’Reilly
2007/2008), ASP.NET Pro (WCF Column),
MSDN, CoDe
• Speaker: Tech Ed, PDC, Dev Connections,
West,
SD West and other international
conferences
• Blogs: www dasblonde net
www.dasblonde.net,
www.thatindigogirl.com
Rich Internet Applications
• Rich Internet Applications (RIAs) include
AJAX and Silverlight clients
• Both run in the browser
• Both rely on asynchronous calls to collect
data from services
d t f i
• Both enable a richer client-side experience
● AJAX using JavaScript
● g g p
Silverlight using code-behind, JavaScript or
dynamic languages (DLR)
Rich Internet Applications and WCF
• How do AJAX and Silverlight clients
communicate with WCF services?
• How should the WCF service be designed
to better support RIAs?
What tools t there t simplify
• Wh t t l are out th to i lif
communications between AJAX or
Silverlight d
Sil li ht and WCF?
• What kind of security models are
available?
WCF Service Design Options
• Protocols:
● SOAP
● Plain-Old-XML
Plain Old XML (POX)
● JavaScript Object Notation (JSON)
● AtomPub/RSS
● Representational State Transfer (REST)
• Implementations:
● WCF services
● ADO.NET Data Services (based on WCF)
SOAP Services
• ServiceContractAttribute
• OperationContractAttribute
• S i H t S i H tF t
ServiceHost, ServiceHostFactory
• BasicHttpBinding
Non SOAP
Non-SOAP Services
• ServiceContractAttribute
• OperationContractAttribute
• WebGetAttribute, WebInvokeAttribute
W bG tAtt ib t W bI k Att ib t
• WebServiceHost/Factory,
WebHttpBehavior
• WebScriptServiceHost/Factory,
p y,
WebScriptEnablingBehavior
• WebHttpBinding
DEMO
• Creating SOAP and RESTful services
AJAX and WCF
• Can use XmlHttpRequest to invoke WCF
services
SOAP POX
• Supports SOAP, POX, or JSON
• POX or JSON services may be RESTful
• Process asynchronous response with
JavaScript
AJAX and WCF
Browser
Page
SOAPService
XmlHttpRequest
POXService
JSONService
DEMO
• Calling WCF services from AJAX
Java Script Proxy
Browser
Script
ScriptManager Reference
Page
/JSONService/js
Generated
Proxy
JSONService
JSONS i
JavaScript Proxy
XmlHttpRequest
/JSONService/
OperationName
ASP.NET AJAX 4.0 Preview 4
• Even more support for AJAX clients to
consume services
• DataContext
● For WCF services
C
• AdoNetDataContext
● For ADO.NET Data Services
• Also much improved experience
y y g y
dynamically binding data from async calls
● But that’s another session ☺
DEMO
• New features for invoking services
Silverlight and WCF
• Can use XmlHttpRequest or WebClient to
invoke WCF services
● SOAP,
Supports SOAP POX or JSON
• SOAP services are supported by Add
Service Reference
● Proxy exposes asynchronous methods
● Very convenient
V i
DEMO
Dealing with SOAP Faults
• WCF services throw FaultException
derivatives to report errors
• Faults are reported with an HTTP error
code 400/500
Carry SOAP envelope with <fault>
• C l ith f lt
according to SOAP 1.1 or 1.2
• Not so meaningful with non-SOAP clients
and services
SOAP Faults and AJAX
non
• FaultException not meaningful to non-
SOAP services
• HTTP 400 bad request by default
• Non-SOAP endpoints should handle
ti differently
exceptions diff tl
• Error handler can provide string message
in 400 error code
pp
• WCF REST Starter kit supports
WebException
SOAP Faults and Silverlight 2
• Anything other than HTTP 200 details are
swallowed by the browser
• Many documented workarounds are
somewhat unacceptable
● Catch d t t f
C t h and return as part of message
● Use message contracts with common base
● Provide i d i just f SL clients
P id a service endpoint j for li
• Acceptable approaches include
● Converting 400/500 errors to 200 at the
service or at the client
DEMO
• Dealing with exceptions
ASP.NET Security
ASP.NET
• ASP NET compatibility allows services to
be processed by the ASP.NET pipeline
IIS,
• IIS Windows or Forms authentication
• Protect service pages along with other
ASP NET resources
ASP.NET
• If you REALLY want to:
● Pass custom headers to services and do
custom authentication
● Or, custom WS* UserName profile
Cross Domain
Cross-Domain Support
• AJAX and Silverlight only allow calls to the
originating domain
● Unless the target domain includes a cross
domain scripting policy
Crossdomain.xml
• Crossdomain xml
● Supported by AJAX or Silverlight
Clientaccesspolicy.xml
• Cli t li l
● Silverlight only, priority over crossdomain.xml
DEMO
Cross domain
• Cross-domain support
Resources
• Learning WCF
● Michele Leroux Bustamante, O’Reilly 2007
● VS2008,
Reprinted with updates for VS2008 July 2008
• My Blog: http://www.dasblonde.net
● S post-conference blog post
See f
for samples from this and other
sessions at Dev Connections!
• Book blog:
www.thatindigogirl.com
Get documents about "