如何通过WCF服务填充Combobox [英] How to populate Combobox through WCF Service

查看:82
本文介绍了如何通过WCF服务填充Combobox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Freinds,



我有一个拥有200000条记录的物品Master。当我通过WCF服务填充组合框时,得到以下错误,但是我已经通过app.config中的最大邮件大小。



最大邮件大小配额已经超过收到的消息(2147483647)。



请指导我如何通过客户端应用程序中的WCF服务填充大量数据。



这里是示例代码。



WCF服务



Hi Freinds,

I am having an item Master with 200000 records. when I populate the combobox through WCF service, gets the follwoing error, however I have passed the maximum message size in the app.config.

The maximum message size quota for incoming messages (2147483647) has been exceeded.

could you please guide me how to fill a huge data through WCF service in client application .

here is the sample Code.

WCF service

public class ItemMaster
{
int ItemId;
string ItemName;
...
}










 List< itemmaster >  GetItemMaster()
{
....
}





客户申请





Client application.

Combobox1.DataSource = cmbService.GetItemMaster();
combobox1.DisplayMember ="ItemName";
combobox1.ValueMember ="ItemId";







谢谢




Thanks

推荐答案

阅读这个 [ ^ ]文章。它应该会有所帮助。



您还可以在绑定配置中增加邮件大小,它会起作用。



BTW,你为什么要将Combobox与那些巨大的价值观绑定在一起?一个正常的人不能一次处理那么多记录。我认为你需要对你的应用程序进行一些重新设计。
Read this[^] article. It should help.

You can also increase the message size in the binding configuration and it will work.

BTW, why are you binding Combobox with that huge set of values? A normal human being cannot process that many records in one go. I think you need a bit of re-designing of your application.


//在wcf服务中

[OperationContract]

public List GetCountry()

{

List listcountry = new List();

using(SqlConnection con = new SqlConnection(connection))

{

使用(SqlCommand cmd = new SqlCommand())

{

cmd.Connection = con;

cmd.CommandText =select * from Country;

con.Open();

SqlDataReader reader = cmd.ExecuteReader();

while(reader.Read())

{

国家/地区=新国家();

country.Id = Convert.ToInt32(reader [Id]。ToString());

country.CountryName = reader [CountryName]。ToString();

listcountry.Add(country);

}

}

}

返回listcountry.ToList();

}





//在你的xaml CS文件中





private void ComboBoxTest_Loaded(对象发送者,RoutedEventArgs e)

{

ServiceReference1.Service1Client connection1 = new ServiceReference1.Service1Client();

connection1.GetCountryCompleted + = new EventHandler(GetCountry);

connection1 .GetCountryAsync();

}



private void GetCountry(Object sender,ServiceReference1.GetCountryCompletedEventArgs e)

{

if(e.Error!= null)

{

MessageBox.Show(未能获得国家+ e.Error.Message);

返回;

}

其他

{

ComboBoxTest.ItemsSource = e.Result.ToList();

ComboBoxTest.DisplayMemberPath =CountryName;

ComboBoxTest.SelectedValuePath =Id;

}

}
//In wcf services
[OperationContract]
public List GetCountry()
{
List listcountry = new List();
using (SqlConnection con=new SqlConnection(connection))
{
using (SqlCommand cmd=new SqlCommand())
{
cmd.Connection = con;
cmd.CommandText = "select * from Country";
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
Country country = new Country();
country.Id = Convert.ToInt32(reader["Id"].ToString());
country.CountryName = reader["CountryName"].ToString();
listcountry.Add(country);
}
}
}
return listcountry.ToList();
}


// In you xaml CS file


private void ComboBoxTest_Loaded(object sender, RoutedEventArgs e)
{
ServiceReference1.Service1Client connection1 = new ServiceReference1.Service1Client();
connection1.GetCountryCompleted += new EventHandler(GetCountry);
connection1.GetCountryAsync();
}

private void GetCountry(Object sender, ServiceReference1.GetCountryCompletedEventArgs e)
{
if (e.Error != null)
{
MessageBox.Show("Fail To Get Country" + e.Error.Message);
return;
}
else
{
ComboBoxTest.ItemsSource = e.Result.ToList();
ComboBoxTest.DisplayMemberPath = "CountryName";
ComboBoxTest.SelectedValuePath = "Id";
}
}


这篇关于如何通过WCF服务填充Combobox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆