【发布时间】:2017-03-10 14:43:24
【问题描述】:
我正在尝试学习 WCF 服务以最终与我们的一个网站合并。
我在我的数据库中创建了一个名为 [TestTable] 的测试表 我已经能够从 Visual Studio 中创建的测试站点成功地将数据写入表中。
我现在正尝试从数据库中填充下拉列表。在这种情况下,是所有状态的列表。
我似乎遗漏了一些东西。我可以调用该服务,它将显示 WCF 测试客户端中的所有状态;但是,我似乎无法弄清楚如何将它返回的列表附加到 ASP.net 下拉列表中。
这是我的 IService1.cs
[ServiceContract]
public interface IService1
{
[OperationContract]
//string GetData(int value);
string InsertApplicantDetails(ApplicantDetails appInfo);
[OperationContract]
List<US_States> GetAllStates();
//CompositeType GetDataUsingDataContract(CompositeType composite);
// TODO: Add your service operations here
}
这是我的 GetAllStates 的 Service1.svc.cs
public List<US_States> GetAllStates()
{
using (JobSeekersEntities db = new JobSeekersEntities())
{
var q = (from us_states in db.US_States
orderby us_states.abbr ascending
select us_states);
List<US_States> list_States = q.ToList<US_States>();
return list_States.ToList();
}
}
在测试网站中,我创建了名为“dropdownStates”的下拉列表。
我已经添加了 ServiceReference 并且它正在工作,因为我可以将值提交到数据库。
我还为下拉列表创建了一个 Load() 事件。
这是我的测试页面。
public partial class TestSubmission : System.Web.UI.Page
{ ServiceReference1.Service1Client objCon = new ServiceReference1.Service1Client();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void dropdownStates_Load(object sender, EventArgs e)
{
//ServiceReference1.Service1Client myCon = new ServiceReference1.Service1Client();
dropdownStates.Items = ????
}
}
任何帮助将不胜感激。感谢您的宝贵时间。
【问题讨论】: