2011-03-17 171 views
1

我有一个wcf服务,它返回一个通用列表:List lstAccount。 我winforms应用程序中的表示层客户端使用代理对象来连接到此服务。从wcf响应到下拉列表的绑定集合

在代理,账户类被这样产生的:

[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "3.0.4506.2152")] 
    [System.SerializableAttribute()] 
    [System.Diagnostics.DebuggerStepThroughAttribute()] 
    [System.ComponentModel.DesignerCategoryAttribute("code")] 
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://schemas.datacontract.org/2004/07/Test.Common")] 
    public partial class Account {} 

当我结合这个lstAccount在我的表现层的窗体上的下拉列表[通过设置DataSource属性],在下拉列表只显示了班级名称“帐户”而不是缩写帐户名称。

this.cblExistingAccounts.DataSource = lstAccount; 
this.cblExistingAccounts.DisplayMember = "Name"; 

我在这里错过了什么?

谢谢。

+0

当您测试在wcftestclient将WebMethod你得到的记录?客户端应该首先调用代理方法,我在这里没有看到... – sajoshi 2011-03-17 07:42:58

+0

是的,我确实从服务获取记录。为简洁起见,我没有在此处添加该代码。 – Jimmy 2011-03-17 07:59:03

回答

1

确保服务端的帐户类的属性使用DataMember属性进行装饰。

编辑:确保你的代理是最新的,尝试刷新它,看看它是否修复了这个问题。

+0

我没有svcUtil工具。我的机器上有DatasvcUtil.exe文件,我可以用它来生成代理吗? – Jimmy 2011-03-17 08:24:52

+0

如果使用Visual Studio“Service Reference”功能创建代理,可以右键单击它并选择“更新服务参考” – 2011-03-17 10:29:03

+0

我在服务器端添加了DataMember属性,再次生成了proy,但结果相同。我知道添加此属性后代理对象中会出现什么差异?谢谢。 – Jimmy 2011-03-17 16:31:33

0

修改样结合:

this.cblExistingAccounts.DataSource = lstAccount; 
this.cblExistingAccounts.DataTextField = "Name"; 
+0

感谢您的回复,但我使用System.Windows.Forms.ComboBox与this.cblExistingAccounts.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;它没有DataTextField属性。 – Jimmy 2011-03-17 08:13:22