Connecting SQL Azure to Windows Phone 7 using WCF
I'm new in programming windows phone 7 but get really tired cuz i spend 3 days on one problem. I search all internet and get some good explanions but without luck - it doesn't work on me program.
I create in SQL Azure one table which i called dbo.Messenger with structure:
Then i make for it WCF wchich should bring me a list of it:
[OperationContract]
List<NoteDto> GetNotes();
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;
}
}
of cource got for each DataMember like this on extra class NoteDto:
[DataMember]
public int id {get; set; }
So after this i make wp7 apps which get listbox which should also be fill afert i click button2
<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>
And this code behind of this:
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");
}
}
public event PropertyChangedEventHandler PropertyChanged; private void RaisePropertyChanged(string propertyName) { PropertyChangedEventHandler propertyChanged = this.PropertyChanged; if ((propertyChanged != null)) { propertyChanged(this, new PropertyChangedEventArgs(propertyName)); } }
void client_GetNotesCompleted(object sender, GetNotesCompletedEventArgs e)
{this.Notes = e.Result; }
When i click button 2 my listbox isn't fill by records from database.
Any idea ? Plz help ?
What kind of binding are you using? recall that only wshttpbinding is not available for WP7. On the other hand, why don't you expose such database with WCF Data Service as OData.
Check it out.
Hope it helpful,
链接地址: http://www.djcxy.com/p/46574.html上一篇: 执行搜索wpf时超时