iis服务器服务有数据 远程的无数据,调用部署在本机IIS服务器的WCF服务并返回数据DataTable,一直报错:远程主机强迫关闭了一个现有的连接。但是服务访问正常,请问怎么解决?...

Hi Ryan0007,

为了确认是不是DataTable相关的代码有问题, 我建议你添加一个新的方法,这个方法只返回一个简单的String, 比如“Hello World”. 如果结果显示只有返回DataTable的方法出错,我建议你把GetClientList这个方法里的代码分享给我们看下。

我对于 DataTable做了下面的测试,是没有问题的。

Service

public DataTable GetTable()

{

MakeParentTable();

DataTable dt = dataSet.Tables[0];

return dt;

}

private System.Data.DataSet dataSet;

private void 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";

// 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";

// Add the column to the table.

table.Columns.Add(column);

// Instantiate the DataSet variable.

dataSet = new DataSet();

// Add the new DataTable to the DataSet.

dataSet.Tables.Add(table);

// Create three new DataRow objects and add

// them to the DataTable

for (int i = 0; i <= 2; i++)

{

row = table.NewRow();

row["id"] = i;

row["ParentItem"] = "ParentItem " + i;

table.Rows.Add(row);

}

}

Client

DbOperationService.DbOperationClient client = new DbOperationService.DbOperationClient();

DataTable dt = client.GetTable();

MessageBox.Show(dt.Rows.Count.ToString());

我建议你测试下上面的代码,看下是否跟你创建的DataTable有关系。

Best Regards,

Edward

MSDN Community Support

Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to

MSDN Support, feel free to contact MSDNFSF@microsoft.com.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值