[英]WCF Web services and Windows Phone
我正在努力使我的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数据模型中,然后在电话应用程序中有一个服务引用,还有2个调用数据的方法,这是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]
}
}
手机应用程序中的2种方法
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;
}
}
}
根据我的评论,尝试以下操作:
void client_DoWorkCompleted(object sender, DoWorkCompletedEventArgs e)
{
if (e.Error == null)
{
listBox1.DisplayMemberPath = "PropertyA";
listBox1.ItemsSource = e.Result;
}
}
其中PropertyA
是要显示的TimeData
上的属性的名称。
就像我说的,我没有可用的Visual Studio来测试它,但是它应该可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.