C# WCF流模式问题
我正在IIS中使用basicHttpBinding(使用流模式)托管WCF服务。WCF web服务使用ADO.Net查询后端SQL Server 2008,并向WCF服务的客户端返回数据表 我对WCF流媒体模式的理解是C# WCF流模式问题,c#,.net,wcf,visual-studio-2008,datatable,C#,.net,Wcf,Visual Studio 2008,Datatable,我正在IIS中使用basicHttpBinding(使用流模式)托管WCF服务。WCF web服务使用ADO.Net查询后端SQL Server 2008,并向WCF服务的客户端返回数据表 我对WCF流媒体模式的理解是 WCF流模式应仅在客户端和服务器端使用固定数量的内存 WCF流模式应该能够在客户端和服务器之间传输任意数量的数据 我的理解正确吗 如果是,我的以下样本违反了这两条规则,我观察到两条违规行为 我发现下面的示例继续消耗内存(从任务管理器的“性能”选项卡,内存使用量增加)。我在同一台机
public class StudentManagement : IStudentManagement
{
public DataTable Poll(int Id)
{
return MakeParentTable();
}
private DataTable MakeParentTable()
{
// Create a new DataTable.
System.Data.DataTable table = new DataTable("ParentTable");
// Declare variables for DataColumn and DataRow objects.
DataColumn column;
DataRow row;
// Create new DataColumn, set DataType,
// ColumnName and add to DataTable.
column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
column.ColumnName = "id";
column.ReadOnly = true;
column.Unique = true;
// Add the Column to the DataColumnCollection.
table.Columns.Add(column);
// Create second column.
column = new DataColumn();
column.DataType = System.Type.GetType("System.String");
column.ColumnName = "ParentItem";
column.AutoIncrement = false;
column.Caption = "ParentItem";
column.ReadOnly = false;
column.Unique = false;
// Add the column to the table.
table.Columns.Add(column);
// Make the ID column the primary key column.
DataColumn[] PrimaryKeyColumns = new DataColumn[1];
PrimaryKeyColumns[0] = table.Columns["id"];
table.PrimaryKey = PrimaryKeyColumns;
// Create three new DataRow objects and add
// them to the DataTable
for (int i = 0; i <= 10000000; i++)
{
row = table.NewRow();
row["id"] = i;
row["ParentItem"] = "ParentItem " + i;
table.Rows.Add(row);
}
return table;
}
}
客户端app.config的流模式配置
<basicHttpBinding>
<binding name="BasicHttpBinding_IStudentManagement" closeTimeout="00:01:00"
openTimeout="00:20:00" receiveTimeout="01:00:00" sendTimeout="01:00:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="1500000000" maxBufferPoolSize="1500000000" maxReceivedMessageSize="1500000000"
messageEncoding="Mtom" textEncoding="utf-8" transferMode="Streamed"
useDefaultWebProxy="true">
<readerQuotas maxDepth="1500000000" maxStringContentLength="1500000000"
maxArrayLength="1500000000" maxBytesPerRead="1500000000" maxNameTableCharCount="1500000000" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
流模式的服务器端web.config
<basicHttpBinding>
<binding name="BasicHttpBinding_IStudentManagement" closeTimeout="00:01:00"
openTimeout="00:20:00" receiveTimeout="01:00:00" sendTimeout="01:00:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="1000000000" maxBufferPoolSize="1000000000" maxReceivedMessageSize="1000000000"
messageEncoding="Mtom" textEncoding="utf-8" transferMode="Streamed"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="1000000000" maxArrayLength="1000000000"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
maxBufferSize属性限制WCF在发送/接收流数据时使用的内存量。但是,您正在将大型对象加载到内存中,然后再将其发送到客户端 首先,我建议您使用DTO(数据传输项目)将数据发送到客户机,如果您需要将那么多数据发送到客户机,则应实现分页机制,以可管理的块传输数据
理论上,您可以使用WCF向客户机发送1000万条记录,但实际上,客户机几乎不需要那么多数据,尤其是一次性数据。maxBufferSize属性限制了WCF在发送/接收流数据时使用的内存量。但是,您正在将大型对象加载到内存中,然后再将其发送到客户端 首先,我建议您使用DTO(数据传输项目)将数据发送到客户机,如果您需要将那么多数据发送到客户机,则应实现分页机制,以可管理的块传输数据
理论上,您可以使用WCF向客户端发送1000万条记录,但实际上,客户端几乎不需要那么多数据,尤其是一次需要这么多数据。在流模式下,您必须使用system.io.stream作为返回类型或参数类型。显然,您没有这样做。在流模式下,您必须使用system.io.stream作为返回类型或参数类型。显然,你没有这样做
<basicHttpBinding>
<binding name="BasicHttpBinding_IStudentManagement" closeTimeout="00:01:00"
openTimeout="00:20:00" receiveTimeout="01:00:00" sendTimeout="01:00:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="1000000000" maxBufferPoolSize="1000000000" maxReceivedMessageSize="1000000000"
messageEncoding="Mtom" textEncoding="utf-8" transferMode="Streamed"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="1000000000" maxArrayLength="1000000000"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>