UWP应用程序无法使用net.tcp连接到Wcf服务

时间:2018-07-02 23:36:36

标签: c# wcf uwp net.tcp

我有一个Wcf服务,该服务已由Intranet内的WinForm应用程序和asp.net网站成功使用。现在,我将WinForm应用程序重写为Uwp应用程序。我安装了最新的Framework 4.7.2和Net.Core 2.1。如何从Uwp使用我的服务?我尝试使用以下方式连接到我的服务:

        var binding = new NetTcpBinding(SecurityMode.Transport);
        binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
        WcfService.WcfServiceClient wcf_client = new
                        WcfService.WcfServiceClient();
        wcf_client.Endpoint.Binding = binding;
        wcf_client.Endpoint.Address = new System.ServiceModel.EndpointAddress("net.tcp://server:8089/TeamCity");
        wcf_client.ClientCredentials.Windows.ClientCredential.UserName = "user";
        wcf_client.ClientCredentials.Windows.ClientCredential.Password = "password";

致电我的服务后

var towers = await wcf_client.GetTowersAsync();

我得到一个错误:

  

at System.Runtime.AsyncResult.End [TAsyncResult](IAsyncResult结果)      在System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult结果)      在System.ServiceModel.Channels.ServiceChannel.EndCall处(字符串操作,Object []输出,IAsyncResult结果)      在System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator。<> c__DisplayClass1_0.b__0(IAsyncResult asyncResult)   ---从之前引发异常的位置开始的堆栈结束跟踪---      在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)      在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)      在System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()      在UwpApp.MainPage.d__1.MoveNext()   ---从之前引发异常的位置开始的堆栈结束跟踪---      在System.Runtime.CompilerServices.AsyncMethodBuilderCore。<> c.b__6_0(对象状态)      在System.Threading.WinRTSynchronizationContext.Invoker.InvokeCore()

0 个答案:

没有答案