App ServicesDeveloper's Guide to Windows 10.ppt

上传人:twoload295 文档编号:378479 上传时间:2018-10-09 格式:PPT 页数:27 大小:783.06KB
下载 相关 举报
App ServicesDeveloper's Guide to Windows 10.ppt_第1页
第1页 / 共27页
App ServicesDeveloper's Guide to Windows 10.ppt_第2页
第2页 / 共27页
App ServicesDeveloper's Guide to Windows 10.ppt_第3页
第3页 / 共27页
App ServicesDeveloper's Guide to Windows 10.ppt_第4页
第4页 / 共27页
App ServicesDeveloper's Guide to Windows 10.ppt_第5页
第5页 / 共27页
亲,该文档总共27页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

1、App Services Developers Guide to Windows 10,Agenda,What are App Services? App Services Scenarios App Services Client App Services Server Debugging Tips Debugging an App Service App Services Details App Service Lifetime Implementing a client SDK Controlling Access Versioning,What are App Services?,Ap

2、p Service: Special case of Background Task,Client App A,Client App B,Background Task,App with App Service,Scenario: Bar Code Scanning,Bar Code decoding App Service,Image bytes in ValueSet or FileToken,Decoded data,Scenario: Enterprise suite of apps,App Service Maintains Inventory cache,Client App A,

3、Client App B,Interact with cloud services,App Service Proximity Reading Services,Think of App Services as Web services on device,App Services Client,AppServiceConnection connection = new AppServiceConnection(); connection.AppServiceName = “microsoftDX-appservicesdemo“; connection.PackageFamilyName =

4、 “24919ArunjeetSingh.InstapaperIt“; AppServiceConnectionStatus connectionStatus = await connection.OpenAsync(); if (connectionStatus = AppServiceConnectionStatus.Success) /Send data to the service var message = new ValueSet(); message.Add(“Command“, “CalcSum“); message.Add(“Value1“, Int32.Parse(Valu

5、e1.Text); message.Add(“Value2“, Int32.Parse(Value2.Text); /Send message and wait for response AppServiceResponse response = await connection.SendMessageAsync(message); if (response.Status = AppServiceResponseStatus.Success) int sum = (int)response.Message“Result“; new MessageDialog(“Result=“ + sum).

6、ShowAsync(); ,App Services Service (1/2),namespace AppServicesDemoTask public sealed class AppServiceTask : IBackgroundTask private static BackgroundTaskDeferral _serviceDeferral; public void Run(IBackgroundTaskInstance taskInstance) var appService = taskInstance.TriggerDetails as AppServiceTriggerD

7、etails; if (appService.Name = “microsoftDX-appservicesdemo“) / Hook up the RequestReceived event handler appService.AppServiceConnection.RequestReceived += RequestReceived; .,App Services Service (2/2),private async void RequestReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs

8、 args) var message = args.Request.Message; / This service uses a Command keyed entry for the client to invoke services from the App Service string command = message“Command“ as string; switch (command) case “DoIt“: var messageDeferral = args.GetDeferral(); int value1 = (int)message“Value1“; . Do som

9、e processing /Set a result to return to the caller var returnMessage = new ValueSet(); returnMessage.Add(“Result“, result); var responseStatus = await args.Request.SendResponseAsync(returnMessage); messageDeferral.Complete(); break; . ,Declaring App Service,Two-way Communication,Client and server ca

10、n keep a two-way chatty communication channel open Client can attach a RequestReceived event handler to its own AppServiceConnection instanceBoth client and server can send and receive messages,AppServiceConnectionStatus connectionStatus = await connection.OpenAsync(); if (connectionStatus = AppServ

11、iceConnectionStatus.Success) connection.RequestReceived += OnRequestReceived; ,Debugging Tips,Getting the PackageFamilyName for the App Service Debugging your App Service,Getting the Service PackageFamilyName,Store Associate App with the Store sets the store assigned PackageFamilyName You dont have

12、to associate your app for testing! Call Package.Current.Id.FamilyName to return PFN to use in debugging,Debugging App Services,Set breakpoints in app service code Check Do not launch but debug my code when it starts in project properties Launch app service foreground app in debugger nothing happens!

13、 Run client app to connect to app service Debugger attaches and breaks on your breakpoint,Demo: App Services,More considerations on App Services,App Service Lifetime,Service is activated on-demand Background Task activated by means of an AppServiceTrigger Client may terminate service by disposing it

14、s AppServiceConnection You can build in capability for your service to shutdown through a message from a client If the invoking app is suspended, app services sponsored by the app will be terminated Insufficient resources may cause launch failure or service termination Invoking app will get AppServi

15、ceConnectionStatus.ResourcesNotAvailable when connecting May get AppServiceResponseStatus.ResourceLimitsExceeded when sending message,What Protocol?,App Services are designed to be flexible and light-weight and are modelled on web REST Web services Simple Request-Response message API Data packaged a

16、s string-keyed ValueSets Easy to use with multiple different payloads When you publish an App Service, you are defining a communications endpoint An App Service endpoint provides the Caller a way to send data to the Callee An App Service endpoint also provides the Caller a way to request return valu

17、es from the Callee and for the Callee to respond with these return values.,App services provides another way for applications to communicate with each other,Nice to do: Implementing a Client SDK ,Wrap the low-level service communication implementation details inside a more functional set of methods

18、Publish a client SDK for your service Distribute as a NuGet package or by other means,Can I restrict access to my App Service?,Build your own caller validation mechanisms on top of app services Simplest is for service provider to whitelist callers based on their PackageFamilyName PackageFamilyName o

19、f caller is passed with every request Possible to build more complicated caller validation mechanisms on top of ValueSets once a connection has been established Whitelist could be followed by explicit X.509 certificate exchange,Versioning,Follow the Web REST API versioning model If you need to make

20、a breaking change to an App Service endpoint, you must expose a new endpoint and provide backward compatibility with the old one,Demo: App Services client library,Final Thoughts,Its not just about XAML Windows App clients! See Calling an App Service from a WPF/WinForms Win32 App https:/ Arun at aruntalkstech,Review,What are App Services? App Services Scenarios App Services Client App Services Server Debugging Tips Debugging an App Service App Services Details App Service Lifetime Building a client API Controlling Access Versioning,

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 教学课件 > 大学教育

copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
备案/许可证编号:苏ICP备17064731号-1