0

I have a wcf service hosted on windows service. WinForm and aspnet site get information from this service. I created Uwp app and connected it to the same service. Uwp can send requests to the service and receive back data. Problem is when service push data to the client using callback. When service broadcasts to app, app gets nothing. Next time service try to broadcast or client try to send request the channel is broken. Client gets no exception, just doesn't receive response. Service gets:

Cannot access a disposed object.

Object name: 'System.ServiceModel.Channels.ServiceChannel'.

No inner exception. The stack is:

Server stack trace: 

at System.ServiceModel.Channels.CommunicationObject.ThrowIfDisposedOrNotOpen() at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:

Host config:

<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 connection:

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 never get called even if service do broadcast to this client.

  • I've created a simple test project that reproduces the issue here: https://github.com/klimkina/CSharp/tree/master/UwpCalculator Calculator working fine until it registers for service messages. After the first message from service (not received) the channel is broken. – Ludmila Klimkina Jul 12 '18 at 18:44
  • target version: (10.0; Build 10586) min version: (10.0; Build 10240) – Ludmila Klimkina Jul 12 '18 at 19:05
  • I've helped you report this issue directly at the following place: https://github.com/dotnet/wcf/issues/3108 – Barry Wang Aug 13 '18 at 08:51
  • Thank you, Barry Wang - MSFT – Ludmila Klimkina Aug 14 '18 at 20:37
  • I've exposed a Web API and connect my UWP to it now. – Ludmila Klimkina Aug 14 '18 at 20:37
  • Hi, I'm one of the developers of WCF on GitHub. Do you ever get any callback happen? I'm wondering if there's a router somewhere dropping the connection after some idle timeout. If this is the case, NetHttpBinding with WebSockets might be a better option as it has a keep-alive mechanism to prevent idle connections from being forgotten about by intermediate routers. – MattC Aug 30 '18 at 21:43

1 Answers1

0

If this http://github.com/klimkina/CSharp/tree/master/UwpCalculator reproduces the issue, I have a fix for the app to work: after adding following declaration for ICalculatorCallback in reference.cs followed by line #157 , the test app work without problem.

[System.ServiceModel.OperationContractAttribute(IsOneWay = true, Action = "http://tempuri.org/ICalculator/BroadcastToClient")]
void BroadcastToClient(string message);

Cause: In reference.cs file of the UWP project, the ICalculatorCallback definition is missing BroadcastToClient(string) method’s declaration although the BroadcastToClient(string) method’s definition is found in the ICalculatorCallback implementation named CalculatorClientCallback.

Mat
  • 1,960
  • 5
  • 25
  • 38