【发布时间】:2013-01-20 12:49:27
【问题描述】:
我正在努力让我的 Web 服务正常工作,只是一个简短的问题。 基本上我遵循了一个教程,因为我是 Windows Phone 和数据库的新手,
"http://studentguru.gr/b/dt008/archive/2010/12/02/querying-a-database-on-windows-phone-7-using-wcf.aspx"
但是我使用的是我自己的数据库,一个在 Visual Studio 中创建的 .sdf 文件
我设法创建了服务、引用和它所说的所有方法。 但是,当我尝试在运行时从服务中获取数据时,它只会返回
Timesheet_System.Servicereference.TimeData
Timesheet_System.Servicereference.TimeData
Timesheet_System.Servicereference.TimeData
Timesheet_System.Servicereference.TimeData
对于数据库中的所有 4 个项目。
有人知道原因吗? 非常感谢。 代码如下:
我在一个 asp.net 站点中有一个数据服务和一个 ado.net 数据模型, 然后我在电话应用程序中有一个服务参考和两种调用数据的方法 这是asp.net应用程序中的数据服务代码
namespace TimesheetDataSite
{
[ServiceContract(Namespace = "")]
[SilverlightFaultBehavior]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1
{
[OperationContract]
public List<TimeData> DoWork()
{
// Add your operation implementation here
using (TimeDataEntities2 entities = new TimeDataEntities2())
{
var alldata = from x in entities.TimeDatas select x;
return alldata.ToList();
}
}
// Add more operations here and mark them with [OperationContract]
}
}
手机应用中的两种方法
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
Service1Client client = new Service1Client();
client.DoWorkCompleted +=
new EventHandler<DoWorkCompletedEventArgs>(client_DoWorkCompleted);
client.DoWorkAsync();
}
void client_DoWorkCompleted(object sender, DoWorkCompletedEventArgs e)
{
if (e.Error == null)
{
listBox1.ItemsSource = e.Result;
}
}
}
【问题讨论】:
-
发布您的代码以便我们提供帮助。
-
完成,如果它有助于我尝试做的是有一个从数据库中获取信息的页面。另一个页面记录时间,并将其发送到数据库。
-
问题是您的
ListBox不知道如何处理TimeData类型,因此它只是在每个实例上调用.ToString()。不幸的是,我目前在这台机器上没有 Visual Studio,但我建议尝试添加行listBox.DisplayMember = "<the property you want to display in the box>"。 -
那将如何呈现,例如使用 SQL 属性名称,例如 ID?
-
查看我的回答。由于您没有给我们
TimeData的定义,所以我只是编造了一些属性名称。