How to make a UWP that will work with the default

2020-04-26 10:26发布

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?

1条回答
闹够了就滚
2楼-- · 2020-04-26 10:57

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 enter image description here
  4. Click Discover, it will default find the wcf service in your solution.Change the namespace to meet your requirement.enter image description here
  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();
    }
    

    enter image description here

查看更多
登录 后发表回答