基于Silverlight 的RIA架构及百度应用杨丹资深.NET架构师微软(中国)陈广琛Web前端工程师百度
议题RIA与应用平台趋势Silverlight 应用架构界面模型逻辑分层网络访问安全机制百度Silverlight应用
RIA与应用平台趋势纯Web在Web上实现通过Web部署界面更美观像桌面应用动画 多媒体开发更高效面向对象语言美工技术协同RichnessWebDesktopRIAWin FormHTMLDHTMLAJAXSilverlightWPFPlug-inReach
Silverlight 架构Silverlight Runtime纯Web界面更美观开发更高效PresentationCoreDRMXAMLMediaCore CLRSmall BCLDebugging Garbage CollectorSecurityExceptionLoader
Silverlight应用架构逻辑分层安全机制界面模型BrowserWeb ServerSilverlightB/LB/LSilverlightB/L网络访问
界面模型如何与HTML页面结合?三种选择RIA 与 HTMLRIA 与 RIA单体 RIA模块粒度松散耦合本地通讯MVC/MVP
RIA与RIA- 本地访问Silverlight与HTML对象:JavaScript接口Silverlight应用之间:本地消息Domain 1Domain 2本地消息接受者Local Message Receiver本地消息发送者Local Message Sender本地消息接受者Local Message Receiver本地消息发送者Local Message Sender
单体RIA- 按需加载Silverlight 应用应用 Package (.xap)In-Package 文件应用程序集 (.dll)Library 程序集Library 程序集Library 程序集Entry PointApplication ClassApplication ClassApplication ClassApplication ClassApplication ClassApplication ClassApplication ClassApplication Class资源文件资源文件资源文件资源文件ExternalPart程序集On-Demand 程序集(缓存)(延后)
界面模型 -控制流转面向页面 vs. 面向GUI页面GUISilverlight 导航:相对于Application 的状态
Navigation Framework:Frame, Page<HyperlinkButtonTargetName = "MainContent“NavigateUri = "/Views/List/Products.xaml"></HyperlinkButton>
逻辑分层多层架构  VS.  C/S 架构Silverlight应用定位逻辑写在何处?与 ASP.NET MVC的关系?
逻辑分层 – 与ASP.NET MVC结合SOAPRESTASP.NET MVC业务逻辑层仅传递用于显示的对象以REST调用为主与ASP.NET MVC 结合 public class CategoryController : Controller{    public ActionResult Products(int id){return Json(prods);// return View();}
网络访问Web Service访问方式不同资源/RESTvs. 调用/RPCREST 具象状态传输URI 资源的状态Http 标准操作Get/PostRPC 简单对象访问协议SOAP方法调用,复杂语义Http-Based Web ServiceSOAPREST
网络访问 - RPC/SOAP 方式服务端处理WCF 支持 SOAP客户端调用 - Proxy使用Visual Studio菜单工具AddService Reference命令行工具SLsvcutil.exeSilverlight 版本的 svcutil.exe基于Channel Model开发最灵活的方式
网络访问 - REST方式服务端处理WCF 支持 REST [OperationContract][WebGet(UriTemplate ="Northwind/Order/{orderId}")]OrderInfoMsgGetOrderInfo(string orderId);客户端调用WebClient数据处理XML: XmlReader, Linq  to XML, XmlSerializerJSON:  Linq to JSON, DataContractJsonSerializerRSS/Atom Feeds:  System.ServiceModel.Syndication
网络访问 - REST 与 SOAP 比较
安全机制认证  ( Authentication )授权  ( Authorization )身份传递 ( Credential )消息加密 ( Encryption )
安全机制 – 身份传递身份信息如何传递给后台服务?Browser-Based (自动)Windows AuthenticationASP.NET Form Authentication/CookiesMessage-Based (手工)URL 参数消息头包含Username/Password 或Token
Browser-Based Authentication    Example with Cookies + Forms AuthE.g.: ASP.NET  loginUser:Password:CredentialsYourDomain.comAuth info (cookie)Service calls + Auth infoBrowser
Browser-Based Authentication	Login through SilverlightYourDomain.comCall with credentials toASP.NET Auth Service User:Password:ASP.NET  Auth ServiceReply contains cookieService calls + Auth infoBrowser
Browser-Based Authentication    Using Windows AuthenticationWindows loginUser:Password:YourDomain.comService calls + CredsBrowser
Browser-Based Authentication: Cross-Domain ThreatMyBank.com LoginUser:Password:CredentialsMyBank.comAuth info (e.g. cookie)Could steal orchange dataif protection wasn’t in place恶意请求 + Auth info恶意程序恶意网站
Message-Based AuthenticationIdentity managed by Silverlight, not the BrowserYourDomain.comUser:Password:Creds are added by Silverlight, not browserNo creds恶意网站Browser
Message-Based Authentication:选择 1: 修改接口[OperationContract]public decimal GetActBal(intactID, string user, string pwd);选择 2: 通过WCF 的 WS-Security 在SOAP包头中自动插入身份信息<basicHttpBinding>   <binding name="myBinding"><security mode="TransportWithMessageCredential"><message clientCredentialType="UserName"/>      </security><httpsTransport/>   </binding></basicHttpBinding>
安全机制  –  认证和授权服务端如何认证和授权?Message-Based 身份if(!OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.IsAuthenticated)   throw new SecurityException();// 标准 WCF方法Browser-Based 身份if(!HttpContext.Current.User.Identity.IsAuthenticated) throw new SecurityException();// ASP.NET Membership
安全机制 – 消息加密完整,真实,防篡改两种选择:传输层加密,消息层加密
Silverlight 应用架构界面模型逻辑分层网络访问安全机制
百度应用Silverlight版百度Hi
界面模型选择单体RIA源自Web版的风格Silverlight 3.0暂时缺乏多窗口模型单体RIA的问题耦合度高,难以维护——来自Web版的经验利用MVC分离来解决
Code-BehindASPX/XAML(View)CS/VB(Code-Behind)从Win/Web Forms到MVC<Button OnClick=“…”>  …</Button>private voidButton_OnClick(…){  …}
从Win/Web Forms到MVCMVCASPX(View)CS/VB(Controller)<form action=“…”>  …</form>public ActionResult  Search(…){ViewData = …;  return View();}ViewData
Silverlight MVC实践BindingXAML(View)CS/VB(Controller)<Button Click=“…”>  …</Button>private voidButton_Click(…){  …Counter.Value++;}Binding
Silverlight MVC实践BuilderXAML(View)CS/VB(Controller)<Button Click=“…”>  …</Button>private voidButton_Click(…){Counter.Value++;builder.Update();}Builder
逻辑分层统一调用百度IM API隐藏后端逻辑百度IM APISilverlight版百度Hi网页版百度Hi第三方客户端(计划支持)
异步模型调用单个异步函数RetrieveUserAsync(username)  .AddCallback(user    => ProcessUser(user));多个异步函数组成工作流Async.Chain()  .Next(context => FirstStep(context))  .Next(context => SecondStep(context))  .Next(context => ThirdStep(context))  .Go(initialContext);
网络访问JSON-RPCJSON易于被不同的客户端解释JavaScriptSilverlightIM接口更像是调用而非资源
安全机制百度PassportAPI式认证与授权认证令牌隐藏实现细节在线会话(Session)会话令牌
百度应用小结MVC模型BindingBuilderAPI划分前后端异步工作流JSON-RPCPassport + Session
参考资源官方站点http://www.silverlight.net/免费空间http://silverlight.live.com/博客http://wpfe.cnblogs.com/http://dotnet.catchen.biz/http://silverlightrocks.com/
疑问和解答
基于Silverlight的RIA架构及百度应用

基于Silverlight的RIA架构及百度应用

Editor's Notes

  • #20 Browser-Based AuthN 如何在Silverlight中实现,有何缺陷
  • #23 跨域访问(Cross-Domain)默认是关闭的可以通过“cross-domain policy file”打开Browser-Based 认证只有以下场景才安全无跨域访问 或只访问有限的几个受信的域其他场景只有Message-Based认证才是安全的
  • #25 <basicHttpBinding> <binding name="myBinding"> <security mode="TransportWithMessageCredential"> <message clientCredentialType="UserName"/> </security> <httpsTransport/> </binding> </basicHttpBinding>