Windows 8.1 Universal 和 Windows 10 UWP 端到端演示

improve this page | report issue


概述

本演示的目的是展示端到端流程:

  1. 在 MobileFirst Operations Console 中注册并下载与 MobileFirst 客户机 SDK 预捆绑的样本应用程序。
  2. 将新的或提供的适配器部署到 MobileFirst Operations Console。
  3. 应用程序逻辑更改为发出资源请求。

最终结果

  • 成功 ping MobileFirst Server。
  • 成功地使用适配器检索数据。

先决条件:

  • 已配置 Visual Studio 2013/5
  • 可选。 MobileFirst CLI(下载
  • 可选。 单机MobileFirst Server(下载

1. 启动 MobileFirst Server

确保您已创建 Mobile Foundation 实例,或者
如果使用 MobileFirst Developer Kit,请导航至服务器的文件夹并运行命令 ./run.cmd

2. 创建应用程序

在浏览器窗口中,通过加载以下 URL 打开 MobileFirst Operations Console:http://your-server-host:server-port/mfpconsole。 如果是本地运行,请使用:http://localhost:9080/mfpconsole。 用户名/密码为 admin/admin

  1. 单击应用程序旁的新建按钮
    • 选择 Windows 平台
    • MFPStarterCSharp.Windows 输入为应用程序标识(对于 Windows),或输入 MFPStarterCSharp.WindowsPhone(对于 Windows Phone)
    • 1.0.0 输入为版本
    • 单击注册应用程序

    注册应用程序

  2. 单击获取起动器代码磁贴,并选择下载 Windows 8.1 或 Windows 10 样本应用程序。

    下载样本应用程序

3. 编辑应用程序逻辑

  1. 打开 Visual Studio 项目。

  2. 选择解决方案的 MainPage.xaml.cs 文件,并将以下代码片段粘贴到 GetAccessToken() 方法:

    try
                    {
           IWorklightClient _newClient = WorklightClient.CreateInstance();
           accessToken = await _newClient.AuthorizationManager.ObtainAccessToken("");
           if (accessToken.IsValidToken &&  accessToken.Value != null &&  accessToken.Value != "")
           {
               System.Diagnostics.Debug.WriteLine("Received the following access token value: " + accessToken.Value);
               titleTextBlock.Text = "Yay!";
               statusTextBlock.Text = "Connected to MobileFirst Server";
    
               Uri adapterPath = new Uri("/adapters/javaAdapter/resource/greet",UriKind.Relative);
               WorklightResourceRequest request = _newClient.ResourceRequest(adapterPath, "GET","");
               request.SetQueryParameter("name", "world");
               WorklightResponse response = await request.Send();
    
               System.Diagnostics.Debug.WriteLine("Success: " + response.ResponseText);
    
             }
         }
         catch (Exception e)
         {
             titleTextBlock.Text = "Uh-oh";
             statusTextBlock.Text = "Client failed to connect to MobileFirst Server";
             System.Diagnostics.Debug.WriteLine("An error occurred: '{0}'", e);
         }
    

4. 部署适配器

下载这一准备好的适配器工件,并通过操作 → 部署适配器操作从 MobileFirst Operations Console 进行部署。

样本应用程序

5. 测试应用程序

  1. 在 Visual Studio 中,选择 mfpclient.resw 文件并将 protocolhostport 属性编辑为针对 MobileFirst Server 的正确的值。
    • 如果使用本地 MobileFirst Server,这些值通常是 httplocalhost9080
    • 如果使用远程 MobileFirst Server(在 IBM Cloud 中),这些值通常是 httpsyour-server-address443
    • 如果要在 IBM Cloud Private 上使用 Kubernetes 集群并且如果部署的类型为 NodePort,那么端口的值通常为 Kubernetes 集群中服务公开的 NodePort

    或者,如果已安装 MobileFirst CLI,那么导航至项目根文件夹并运行命令 mfpdev app register。 如果使用远程 MobileFirst Server,那么运行命令 mfpdev server add 来添加服务器,后跟(例如):mfpdev app register myIBMCloudServer

  2. 运行应用程序按钮。

结果

  • 单击 Ping MobileFirst Server 按钮将显示已连接到 MobileFirst Server
  • 如果应用程序能够连接到 MobileFirst Server,那么将使用部署的 Java 适配器进行资源请求调用。

然后,适配器响应将列显在 Visual Studio 的 Outpout 控制台中。

成功从 MobileFirst Server 调用了资源的应用程序的图像

后续步骤

要了解有关在应用程序中使用适配器,如何集成附加服务(如推送通知),使用 MobileFirst 安全框架及其他内容的更多信息,请:

Inclusive terminology note: The Mobile First Platform team is making changes to support the IBM® initiative to replace racially biased and other discriminatory language in our code and content with more inclusive language. While IBM values the use of inclusive language, terms that are outside of IBM's direct influence are sometimes required for the sake of maintaining user understanding. As other industry leaders join IBM in embracing the use of inclusive language, IBM will continue to update the documentation to reflect those changes.
Last modified on June 01, 2020