我有一个托管在 Windows 服务上的 wcf 服务。WinForm 和 aspnet 站点从该服务中获取信息。我创建了 Uwp 应用程序并将其连接到相同的服务。Uwp 可以向服务发送请求并接收返回的数据。问题是当服务使用回调将数据推送到客户端时。当服务向应用广播时,应用什么也得不到。下次服务尝试广播或客户端尝试发送请求时,频道已损坏。客户端没有异常,只是没有收到响应。服务获得:
Cannot access a disposed object.
对象名称:“System.ServiceModel.Channels.ServiceChannel”。
没有内在的例外。堆栈是:
Server stack trace:
在 System.ServiceModel.Channels.CommunicationObject.ThrowIfDisposedOrNotOpen() 在 System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) 在 System.ServiceModel。 Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
在 [0] 处重新抛出异常:
主机配置:
<system.serviceModel>
<services>
<!-- This section is optional with the new configuration model
introduced in .NET Framework 4. -->
<service behaviorConfiguration="ServiceBehavior"
name="TL.TrayNotify.WcfService.WcfService">
<host>
<baseAddresses>
<add baseAddress="net.tcp://server:8089/TeamCity"/>
</baseAddresses>
</host>
<endpoint address="net.tcp://server:8089/TeamCityService/TeamCity/tcp"
binding="netTcpBinding" contract="TL.TrayNotify.WcfService.IWcfService"
bindingConfiguration="tcpBinding">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="net.tcp://server:8090/Calculator/mex" binding="mexTcpBinding"
contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="true "/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding name="tcpBinding">
<security mode="None"></security>
<reliableSession enabled="false" inactivityTimeout="00:20:00" />
</binding>
</netTcpBinding>
</bindings>
UWP 连接:
NetTcpBinding tcpBinding = new NetTcpBinding();
tcpBinding.Security.Mode = SecurityMode.None;
tcpBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
tcpBinding.Security.Message.ClientCredentialType = MessageCredentialType.None;
//new client
m_client = new WcfServiceClient(tcpBinding, new EndpointAddress("net.tcp://server:8089/TeamCityService/TeamCity/tcp"));
m_client.ClientCredentials.Windows.ClientCredential.UserName = "user";
m_client.ClientCredentials.Windows.ClientCredential.Password = "password";
//bind call back event
m_client.BroadcastToClientReceived += MyTeamCityClient_ReceiveTeamCityBroadcastReceived;
await m_client.OpenAsync();
await this.m_client.RegisterClientAsync(m_deviceName);
即使服务向该客户端广播,MyTeamCityClient_ReceiveTeamCityBroadcastReceived也永远不会被调用。