[英]Push message from wcf service to Windows Universal App
我在Windows服務上托管了WCF服務。 WinForm和aspnet站點從此服務獲取信息。 我創建了Uwp應用程序並將其連接到同一服務。 Uwp可以向服務發送請求並接收回數據。 問題是服務使用回調將數據推送到客戶端時。 當服務廣播到應用程序時,應用程序一無所獲。 下次服務嘗試廣播或客戶端嘗試發送請求時,頻道已斷開。 客戶端沒有例外,只是沒有收到響應。 服務獲得:
Cannot access a disposed object.
對象名稱:“ System.ServiceModel.Channels.ServiceChannel”。
沒有內部異常。 堆棧是:
Server stack trace:
在System.ServiceModel.Channels.ServiceChannel.Call處System.ServiceModel.Channels.CommunicationObject.ThrowIfDisposedOrNotOpen()處(字符串操作,布爾型單向,ProxyOperationRuntime操作,Object [] ins,Object [] outs,TimeSpan超時)。 System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage消息)上的Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime操作)
異常重新拋出為[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 。
如果此http://github.com/klimkina/CSharp/tree/master/UwpCalculator重現了該問題,則我已解決了該應用程序的問題:在reference.cs中添加ICalculatorCallback的以下聲明后,接着#157行,測試應用程序正常工作。
[System.ServiceModel.OperationContractAttribute(IsOneWay = true, Action = "http://tempuri.org/ICalculator/BroadcastToClient")]
void BroadcastToClient(string message);
原因:在UWP項目的reference.cs文件中,盡管在名為CalculatorClientCallback
的ICalculatorCallback
實現中找到了BroadcastToClient(string)
方法的定義,但ICalculatorCallback
定義缺少BroadcastToClient(string)
方法的聲明。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.