简体   繁体   中英

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 inte.net 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 with structure: ,其结构如下:

  • id (PK, not null)
  • category (nvarchar(30), null)
  • message (nvarchar(max), null)
  • description (nvarchar(200), null)

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,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM