DataTables的WCF错误:从管道读取错误:无法识别的错误109(0x6d)。

时间:2018-09-21 11:34:02

标签: c# wcf

我有一个WCF服务,该服务使用NetNamedPipeBinding对象作为基础通信机制。文档指出DataTables是可序列化的,因此我认为传递DataTables可以工作。 WCF服务中定义的功能签名如下:

[OperationContract]
DataTable GetRandomDataTable();

该函数只是使用随机引导填充DataTable:

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;
    }

此调用始终导致以下异常:

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)

仅返回一个空的DataTable而不填充行或列具有完全相同的效果。我已经在带有.NET 4.6.2的64位Windows 7和64位Windows 10(1709)计算机上观察到了这一点。绑定管道初始化如下:

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();

我是否忽略了一些明显的问题,我茫然地解释了为什么呼叫会以这种方式失败?

1 个答案:

答案 0 :(得分:1)

我已经读到WCF只能序列化具有指定名称的数据表

DataTable dataTable = new DataTable("myTable");

如果这不起作用,则可以在app.config中启用WCF跟踪以诊断问题。参见https://docs.microsoft.com/en-us/dotnet/framework/wcf/diagnostics/tracing/configuring-tracing