如何制作可与默认 WCF 服务应用程序一起使用的 UWP [英] How to make a UWP that will work with the default WCF Service application

查看:42
本文介绍了如何制作可与默认 WCF 服务应用程序一起使用的 UWP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您创建一个新项目 WCF Service Application C#,它将创建一个 Web 服务并启动它.

但是没有关于如何从客户端实际与它通信,或者甚至如何编写它的信息.

将与该服务通信的 UWP 客户端是什么样的?

解决方案

如何制作可与默认 WCF 服务应用程序一起使用的 UWP

  1. 创建一个默认的 WCF 服务应用程序并像之前一样启动它.

  2. 按照

  3. 点击发现,它会默认在您的解决方案中找到 wcf 服务.更改命名空间以满足您的要求.
  4. 将以下代码添加到按钮单击事件句柄.然后运行 ​​uwp 您将看到 GetData 结果.

    private async void BtnConnectWcf_Click(object sender, RoutedEventArgs e){ToDoService.Service1Client 客户端 = new ToDoService.Service1Client();等待新的 Windows.UI.Popups.MessageDialog(client.GetDataAsync(10).Result.ToString()).ShowAsync();等待 client.CloseAsync();}

If you create a new project, WCF Service Application C#, it makes a web service and starts it up.

But there is no information on how to actually communicate with it from a client, or how to even write that.

What does the UWP client look like which will communicate with that service?

解决方案

How to make a UWP that will work with the default WCF Service application

  1. Create a default WCF Service application and start it up as you have already did.

  2. Create a Universal Windows Blank App by following Create a "Hello, world" app (XAML) in the same solution.

  3. Add service reference for your universal app
  4. Click Discover, it will default find the wcf service in your solution.Change the namespace to meet your requirement.
  5. Add following code to a button click event handle.Then run uwp you will see the GetData Result.

    private async void BtnConnectWcf_Click(object sender, RoutedEventArgs e)
    {
        ToDoService.Service1Client client = new ToDoService.Service1Client();       
        await new Windows.UI.Popups.MessageDialog(client.GetDataAsync(10).Result.ToString()).ShowAsync();
        await client.CloseAsync();
    }
    

这篇关于如何制作可与默认 WCF 服务应用程序一起使用的 UWP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆