Search code examples
c#wcf

WCF Error with DataTables: There was an error reading from the pipe: Unrecognized error 109 (0x6d).'


I have a WCF service that uses a NetNamedPipeBinding object as the underlying communication mechanism. The documentation states that DataTables are serializable so I assumed passing DataTables would work. The signature of the function as defined in the WCF service is as follows:

[OperationContract]
DataTable GetRandomDataTable();

The function just populates the DataTable with random guids:

public DataTable GetRandomDataTable()
    {
        DataTable dataTable = new DataTable();
        dataTable.Columns.Add("ONE", typeof(string));
        dataTable.Columns.Add("TWO", typeof(string));
        dataTable.Columns.Add("THREE", typeof(string));


        for (int i = 0; i < 25; i++)
        {
            dataTable.Rows.Add(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
        }

        return dataTable;
    }

This call always leads to the following exception:

System.ServiceModel.CommunicationException: 'There was an error reading from the pipe: Unrecognized error 109 (0x6d).'
 at System.ServiceModel.Channels.PipeConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
 at System.ServiceModel.Channels.DelegatingConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout) 
 at System.ServiceModel.Channels.ConnectionStream.Read(Byte[] buffer, Int32 offset, Int32 count) 
 at System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count)
 at System.Net.Security.NegotiateStream.StartFrameHeader(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
 at System.Net.Security.NegotiateStream.ProcessRead(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)

Simply returning an empty DataTable without populating the rows or columns has exactly the same effect. I have observed this on 64-bit Windows 7 and 64-bit Windows 10 (1709) machines with .NET 4.6.2. The binding pipe is initialised as follows:

NetNamedPipeBinding pipeBinding = new NetNamedPipeBinding();
pipeBinding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
pipeBinding.MaxBufferSize = int.MaxValue;
pipeBinding.MaxReceivedMessageSize = int.MaxValue;
IService1 channel = new ChannelFactory<IService1>(pipeBinding, new EndpointAddress("net.pipe://localhost/WCFTests")).CreateChannel();

Is there some obvious issue that I overlooking, I am at loss to explain why the call would fail in this way?


Solution

  • I've read that WCF can only serialize DataTable's that have a name specified

    DataTable dataTable = new DataTable("myTable");
    

    If that doesn't work, you can enable WCF tracing in your app.config to diagnose the issue. See https://learn.microsoft.com/en-us/dotnet/framework/wcf/diagnostics/tracing/configuring-tracing