1 / 36

Open Data Protocol ( OData )     と WCF Data Services によるサービスの作成

セッション ID : T4-303. Open Data Protocol ( OData )     と WCF Data Services によるサービスの作成. マイクロソフト株式会社 デベロッパー&プラットフォーム統括本部 エバンジェリスト 井上大輔. セッションの目的 Open Data Protocol の What WCF Data Services の How セッションのゴール Open Data Protocol の“ 多様性 ”を 認識 WCF Data Services の“ 手軽さ ”を認識.

bruce-ellis
Télécharger la présentation

Open Data Protocol ( OData )     と WCF Data Services によるサービスの作成

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. セッション ID: T4-303 Open Data Protocol (OData)    とWCF Data Servicesによるサービスの作成 マイクロソフト株式会社 デベロッパー&プラットフォーム統括本部 エバンジェリスト 井上大輔

  2. セッションの目的 Open Data Protocol の What WCF Data Servicesの How セッションのゴール Open Data Protocol の“多様性”を認識 WCF Data Services の“手軽さ”を認識 セッションの目的とゴールSessionObjectives and Takeaways

  3. アジェンダ • Open Data Protocol (OData) とは ? • ~ 特徴とその価値 ~ • WCF Data Servicesによる開発 • ~ 手軽なサービス開発 ~ • WCF Data Servicesのセキュリティ • ~ 認証と承認 ~

  4. Open Data Protocol (OData) とは? ~ 特徴とその価値 ~

  5. クラウド時代のデータ共有 売上 ニュース 店舗 顧客 SNS 人事 政府 地図 学術 メール リサーチ 見積 株価 辞書 イベント 図面 受注 時刻表 商品カタログ 入出庫 在庫 Server Mobile TV/Game PC

  6. ODataとは ? • データ共有用のRESTfulプロトコル • 様々な環境でデータを共有するための規約 • AtomPubの拡張セット • 構造化データ、CRUD 操作、URI による複雑なクエリ (クエリ式)、JSON フォーマット • Open Specification Promise の基でリリース • 多くの製品やテクノロジで対応 • サーバー • クライアント HTTP/ REST

  7. ご参考~ URI クエリ式 ~

  8. OData対応~ サーバー ~ • 製品やテクノロジ • SharePoint 2010 • Windows Azure Storage • SQL Azure • WCF Data Services • WCF RIA Services • SQL Server Reporting Services 2008 R2 • IBM WebSphereeXtremeScale • odata4j(Google AppEngine) • など • 外部サービス • Tech·Ed 2010 • MIX 10 • Netflix • Vancouver’s vanGuide • Open Government Data Initiative • Open Science Data Initiative • など

  9. OData対応~ クライアント ~ • アプリ • Excel + PowerPivot • ODataExplorer • OData PowerShell Explorer • iPhone OData Browser • LINQPad • Sesame • など • ライブラリ • .NET • Silverlight • Windows Phone 7 • iPhone、iPad (Objective-C) • Android (odata4j) • jQuery • Java • PHP • Ruby • など

  10. 多様な環境への適用 • 全ての層を横断した HTTP/REST の適用 • デバイス、OS、クラウド、DB、UI

  11. + OData WCF ADO.NET Data Services による開発 ~ 手軽なサービス開発 ~

  12. WCF の全体像 Programming Model Core Services Web HTTP Services Data Services RIA Services Workflow Services Service Model Data Contract Service Contract Service Behavior Channel Model Formats (Atom, JSON, XML,…) Transports (HTTP, TCP, …) Protocols (SOAP, HTTP, OData,…)

  13. WCFData Services とは ?~ サーバー ~ • データの CRUD 処理に特化して手軽に RESTfulなサービス開発を実現 • サービス層から DAL へ直接アクセス • ODataとしてデータを公開 • 様々な環境に対応したアプリやライブラリを提供 クライアント サーバー Web サーバー (ASP.NET Application Server) CRUD 処理 サービス ビジネス データ アクセス DB WCF OData WCF Data Services ADO.NET EF など Business Logic SOAP など

  14. DEMO WCF Data Services による手軽なサービス開発 ~ サーバー ~ クライアント サーバー OData

  15. ご参考~ データの公開 (サーバー) ~ public class pubsDataService : DataService< pubsEntities> { public static void InitializeService(DataServiceConfigurationconfig) { config.SetEntitySetAccessRule("*", EntitySetRights.All); config.SetEntitySetPageSize("*", 2); config.DataServiceBehavior.MaxProtocolVersion= DataServiceProtocolVersion.V2; } } データ ソース アクセス ルール ページ サイズ

  16. WCFData Services とは ?~ クライアント ~ • .NET 専用クライアント ライブラリ • サービス操作用プロキシ クラスを自動生成 • LINQ を活用した柔軟なクエリ • 追加、更新、削除処理 • 変更管理の実装を含む クライアント サーバー OData プロキシ クラス

  17. DEMO サービスの利用 ~ .NET ライブラリ ~ クライアント サーバー OData プロキシ クラス

  18. ご参考~ LINQ を使ったクエリ(クライアント) ~ プロキシ クラス pubsEntitiescontext = new pubsEntities(new Uri("http://localhost.:8582/pubsDataService.svc/")); varquery = (from e in context.employees where e.job_lvl > 100 orderbye.hire_date select new { name = e.fname + " " + e.lname, hire_date= e.hire_date, job_desc= e.job.job_desc }).Skip(3).Take(2).ToList(); int count = query.Count(); LINQ を利用した様々なデータ操作

  19. ご参考~ データの追加 (クライアント) ~ pubsEntitiescontext = new pubsEntities(new Uri("http://localhost.:8582/pubsDataService.svc/")); employee emp = new employee { emp_id = “MAP88185M”, fname = “Daisuke”,・ ・ ・}; context.AddToemployees(emp); context.SaveChanges(); データの追加を サーバーへリクエスト

  20. Silverlight で利用するには ? • Silverlight 専用クライアント ライブラリ • サービス操作用プロキシ クラスを自動生成 • Silverlight の特徴 • クライアントのブラウザーで動作 • データベースへの直接アクセスは不可 • サーバー上のデータはサービスを通じて操作 • サービスへのアクセスはすべて非同期処理 クライアント サーバー 非同期 OData プロキシ クラス

  21. DEMO サービスの利用 ~ Silverlight ライブラリ ~ サーバー クライアント 非同期 OData プロキシ クラス

  22. ご参考~ 非同期クエリ (Silverlight) ~ private void button1_Click(object sender, RoutedEventArgs e) { pubsEntitiescontext = new pubsEntities(new Uri("pubsDS.svc", UriKind.RelativeOrAbsolute)); varquery = (from emp in context.employees select emp) as DataServiceQuery<employee>; query.BeginExecute(EmployeesQueryCompleted, query); } private void EmployeesQueryCompleted(IAsyncResult result) { Dispatcher.BeginInvoke(() => { varquery = result.AsyncState as DataServiceQuery<employee>; IEnumerable<employee> employees = query.EndExecute(result).ToList(); dataGrid1.ItemsSource = employees; }); } URL の指定は不要 非同期クエリ処理開始 非同期コールバック メソッドの実装 非同期クエリ処理終了

  23. ご参考~ 非同期クエリと双方向バインド (Silverlight) ~ private void button2_Click(object sender, RoutedEventArgs e) { pubsEntitiescontext = new pubsEntities(new Uri("pubsDS.svc", UriKind.RelativeOrAbsolute)); varquery = (from emp in context.employees select emp) as DataServiceQuery<employee>; varcollection = new DataServiceCollection<employee>(); dataGrid1.ItemsSource= collection; collection.LoadAsync(query); } 双方向バインド コレクション 非同期クエリ処理

  24. ご参考~ 非同期データ追加(Silverlight) ~ private void button3_Click(object sender, RoutedEventArgs e) { pubsEntitiescontext = new pubsEntities(new Uri("pubsDS.svc", UriKind.RelativeOrAbsolute)); employee emp = new employee { emp_id = “MAP88184M”, fname= “Daisuke”, lname = “Inoue”, ・・ ・}; context.AddToemployees(emp); context.BeginSaveChanges(SaveChangesOptions.Batch, OnAddEmployees, context); } private void OnAddEmployees(IAsyncResult result) { Dispatcher.BeginInvoke(() => { pubsEntitiescontext = result.AsyncState as pubsEntities; DataServiceResponseresponse = context.EndSaveChanges(result); }); } 非同期追加処理開始 非同期処理 コールバック メソッドの実装 非同期追加処理終了

  25. WCF Data Services のセキュリティ ~ 認証と承認 ~

  26. 認証と承認 • 認証 (Authentication) • 誰であるかを特定すること (ログイン) • 承認、認可 (Authorization) • リソースへのアクセス制御 クライアント サーバー Web サーバー ASP.NET IIS WCF Data Services DB フォーム 認証など Windows 認証など QueryInterceptor ChangeInterceptor SetEntitySetAccessRule OData ACL  設定 ファイル

  27. ご参考~ Windows 資格情報の取得 (クライアント) ~ context.Credentials = CredentialCache.DefaultCredentials; ※ デフォルト true context.UseDefaultCredentials = true;

  28. 承認、認可 (Authorization) • IIS • Windows 認証の場合、 エクスプローラーのプロパティ ウィンドウから ACL で指定 • ASP.NET • 設定ファイル (Web.config) の <authorization> 要素で指定 • WCF Data Services • QueryInterceptor • 参照処理でカスタム ロジックを割り込ませる属性 • ChangeInterceptor • 参照以外の処理でカスタム ロジックを割り込ませる属性 • SetEntitySetAccessRule • エンティティ セット単位でアクセス権を指定

  29. ご参考~ QueryInterceptor(サーバー) ~ エンティティ セット (employees) の参照で割り込み発生 [QueryInterceptor("employees")] public Expression<Func<employee, bool>> empfilter(){ if (!HttpContext.Current.User.Identity.IsAuthenticated) return (employee e) => false; var id = HttpContext.Current.User.Identity.Name; if (id == "Administrator") return (employee e) => true; else return (employee e) => e.emp_id == id; }

  30. ご参考~ ChangeInterceptor (サーバー) ~ エンティティ セット (employees) の参照以外で割り込み発生 [ChangeInterceptor("employees")] public void OnChangeEmployees(employee e, UpdateOperationsoperations) { if (!HttpContext.Current.User.Identity.IsAuthenticated) throw new DataServiceException(403, "Access Denied"); varid = HttpContext.Current.User.Identity.Name; if (id != "Administrator") { if (id != e.emp_id) throw new DataServiceException(403, "Access Denied"); if (operations == UpdateOperations.Add|| operations == UpdateOperations.Delete) throw new DataServiceException(403, "Access Denied"); } } オペレーションの指定

  31. ご参考~ EntitySetRights で指定可能なメンバー ~ 複数指定 config.SetEntitySetAccessRule(“employees", EntitySetRights.AllRead| EntitySetRights.WriteDelete);

  32. まとめ • ODataは今後のクラウド時代を見据えたデータ共有プロトコル • ODataに対応することで様々な環境で データを共有 • WCF Data Services を用いて多機能な OData対応のサービスを手軽に開発

  33. 関連セッション T4-402:ADO.NET Entity Framework ディープ ダイブ ~ EF 4 アーキテクチャと実践的活用 ~ T6-401:WCF RIA Services を使った Silverlight 4 アプリケーション開発 ~ 迅速性と効率性の追求 ~ T1-309:Windows Azure ストレージ詳説 T6-312:Windows Communication Foundation 4 における新機能のポイント ~ REST サービスからワークフロー サービスまで ~

  34. リファレンス 講師のブログ http://blogs.msdn.com/b/daisukei 講師の Twitter http://twitter.com/daisukei777 データ プラットフォーム (データ アクセス) 開発 http://msdn.microsoft.com/ja-jp/data/default.aspx Open Data Protocol 本家サイト http://www.odata.org/

  35. ご清聴ありがとうございました。 T4-303 アンケートにご協力ください。

More Related