This project has moved. For the latest updates, please go here.

silverlight twitter search response empty

Jun 16, 2011 at 1:23 PM

example source -

var queryResult =
    (from search in m_twitterCtx.Search
     where search.Type == SearchType.Search &&
     search.Query == "LINQ to Twitter"
     select search)

request url -


but SearchRequestProcessor.cs in

public List<T> ProcessResults(string responseXml)


   XElement twitterResponse = XElement.Parse(responseXml);


responseXml is empty


Help me!

Jun 16, 2011 at 2:47 PM


Silverlight queries are different because they must occur asynchronously.  In LINQ to Twitter, I chose an idiom that is close to the way Silverlight naturally works. That means queryResult won't hold any values.  To get results, you would use AsyncCallback, like this:

            var result =
                (from tweet in m_twitterCtx.Status
                 where tweet.Type == StatusType.Friends
                 select tweet)
                .AsyncCallback(tweets =>
                    Dispatcher.BeginInvoke(() =>
                        var projectedTweets =
                           (from tweet in tweets
                            select new MyTweet
                                ScreenName = tweet.User.Identifier.ScreenName,
                                Tweet = tweet.Text

                        FriendsDataGrid.ItemsSource = projectedTweets;

The AsyncCallback is an extension method that takes an Action<T> delegate.  You could reference a separate handler method if you prefer.  I used Dispatcher.BeginInvoke with a lambda also, but it's up to you how you marshal back onto the UI thread.  Because of deferred execution, you need to use an extension method that materializes the query.  As you can see, I used SingleOrDefault.  The parameter to the Action lambda, tweets, contains your results.