从UWP应用程序(Raspberry PI 3)消耗WCF服务时出错

时间:2017-12-26 11:46:37

标签: c# wcf uwp

我构建了一个简单的IoT UWP应用程序,其中包含1个按钮和1个文本字段。 按下按钮将从WCF服务调用一个函数,并在文本字段中显示结果。

  • 我设计了我的应用
  • 在同一个VS项目中,我使用
  • 中的默认函数创建了一个新的WCF应用程序
  • 我添加了WCF应用程序作为服务参考。
  • 编译UWP应用程序后,我没有遇到任何问题。
  • 只要按下按钮,我就会收到以下错误消息:

    Exception thrown: 'System.Exception' in System.Private.CoreLib.dll Exception thrown: 'System.Exception' in System.Private.CoreLib.dll Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.ServiceModel.dll Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll Exception thrown: 'System.Net.Http.HttpRequestException' in System.Net.Http.dll Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll Exception thrown: 'System.ServiceModel.CommunicationException' in System.Private.ServiceModel.dll Exception thrown: 'System.ServiceModel.CommunicationException' in System.Private.CoreLib.dll Exception thrown: 'System.ServiceModel.CommunicationException' in System.Private.CoreLib.dll Exception thrown: 'System.ServiceModel.CommunicationException' in System.Private.ServiceModel.dll Exception thrown: 'System.ServiceModel.CommunicationException' in System.Private.CoreLib.dll An exception of type 'System.ServiceModel.CommunicationException' occurred in System.Private.CoreLib.dll but was not handled in user code Additional information: net_http_client_execution_error

我的UWP中按钮的事件处理程序如下所示:

private async void  button_GetData_Click(object sender, RoutedEventArgs e)
    {            
            Service1Client cl = new Service1Client();
            await cl.OpenAsync();
            var res = await cl.GetDataAsync(12);
            txtData.Text += res;
    }

我的服务如下:

using System;
namespace WCF_Temp
    {
    public class Service1 : IService1
    {
        public string GetData(int value)
        {
        return string.Format("You entered: {0}", value);
        }
    }

我没有想法......有人遇到同样的麻烦吗?

提前致谢!     }

1 个答案:

答案 0 :(得分:1)

您的代码在您的WCF中很简单,您的客户端代码也很简单。因此,如果只检查您的代码段,很难找到您的问题。

您可能需要进行故障排除。例如,

  1. 您可以在WCF和客户端代码中添加一些断点进行调试。
  2. 您可以在自己喜欢的浏览器中输入WCF服务地址,以测试您的服务是否有效。如果它在浏览器中运行良好,您可能需要检查是否在UWP客户端中正确添加了对WCF服务的引用。
  3. 您可以使用fiddler来捕获流量并检查请求是否已成功发送。
  4. 此外,如果您不知道如何调试WCF服务,请查看此文档Debugging WCF Services