C# 使用WCF将SQL Azure连接到Windows Phone 7
我刚开始编程WindowsPhone7,但我真的很累,因为我花了3天时间解决一个问题。我搜索了所有的互联网,并得到了一些好的解释,但没有运气-它不工作对我的程序 我在SQL Azure中创建了一个名为dbo.Messenger的表,其结构如下: id PK,不为空 类别nvarchar30,空 消息nvarcharmax,null 说明nvarchar200,空 然后我为它制作WCF WCH,它应该给我一个列表: 所以,在这之后,我制作了wp7应用程序,它会得到列表框,在我点击按钮2之后,列表框也会被填充C# 使用WCF将SQL Azure连接到Windows Phone 7,c#,wcf,windows-phone-7,azure-sql-database,C#,Wcf,Windows Phone 7,Azure Sql Database,我刚开始编程WindowsPhone7,但我真的很累,因为我花了3天时间解决一个问题。我搜索了所有的互联网,并得到了一些好的解释,但没有运气-它不工作对我的程序 我在SQL Azure中创建了一个名为dbo.Messenger的表,其结构如下: id PK,不为空 类别nvarchar30,空 消息nvarcharmax,null 说明nvarchar200,空 然后我为它制作WCF WCH,它应该给我一个列表: 所以,在这之后,我制作了wp7应用程序,它会得到列表框,在我点击按钮2之后,列表框
<ListBox Height="431" HorizontalAlignment="Left" Margin="12,199,0,0" Name="listBox1" VerticalAlignment="Top" Width="438"
ItemsSource="{Binding Notes}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding category}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
当我点击按钮2时,我的列表框并没有被数据库中的记录填充。
有什么想法吗?请帮忙 您使用的是哪种绑定?回想一下,只有wshttpbinding不可用于WP7。另一方面,为什么不使用WCF数据服务公开这样的数据库呢
希望对您有所帮助,您不知道您的代码是否无法获取注释,或者屏幕是否无法响应更改。我会将button2\u Click更改为仅将其设置为静态值。我说的是button2\u Click中的类似内容:this.Notes=new List{new NoteDto{id=1,category=Foo};调试101..找出哪个部分出现故障。然后找出原因。我使用默认绑定,自从使用asp.net 4.0创建项目以来,在web.config中没有任何更改。WCF的工程性质,因为我试图用它来获得一个记录,以填补文本框,它是好的,得到这个问题与列表只。我可以尝试oData,但正如我所看到的,我需要visual studio 2010,而不是使用我预先提供的express:我认为默认绑定是MEX,这两种绑定都不受支持。尝试使用WCF WCF编辑器添加basichttpbinding,或仅通过添加:
public List<NoteDto> GetNotes()
{
using (var context = new WP7mgrEntities())
{
var notes = (from eachNote in context.Messenger
orderby eachNote.id ascending
select new NoteDto
{
id = eachNote.id,
category= eachNote.category,
description= eachNote.description,
message= eachNote.message,
}
).ToList();
return notes;
}
}
[DataMember]
public int id {get; set; }
<ListBox Height="431" HorizontalAlignment="Left" Margin="12,199,0,0" Name="listBox1" VerticalAlignment="Top" Width="438"
ItemsSource="{Binding Notes}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding category}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
private void button2_Click(object sender, RoutedEventArgs e)
{
Service1Client client = new Service1Client();
client.GetNotesCompleted += new EventHandler<GetNotesCompletedEventArgs>(client_GetNotesCompleted);
this.Notes = new ObservableCollection<NoteDto>();
}
private ObservableCollection<NoteDto> _notes;
public ObservableCollection<NoteDto> Notes
{
get { return _notes; }
set { _notes = value;
this.RaisePropertyChanged("Notes");
}
}
void client_GetNotesCompleted(object sender, GetNotesCompletedEventArgs e)
{this.Notes = e.Result; }