代码之家  ›  专栏  ›  技术社区  ›  pavanred

支持WindowsPhone7和silverlight的REST库?

  •  1
  • pavanred  · 技术社区  · 14 年前

    4 回复  |  直到 14 年前
        1
  •  1
  •   Nigel Sampson    14 年前

    我在使用 Hammock 尤其是当需要像OAuth这样的东西时。

        2
  •  1
  •   ctacke    14 年前

    你到底是什么意思?你是说图书馆的“助手”可以帮你完成 RestSharp supports Windows Phone )?

    或者你的意思完全不同?

        3
  •  0
  •   Guffa    14 年前

    你可以使用 HttpWebRequest WebClient

        4
  •  0
  •   Amir    14 年前

    Restful-Silverlight 是我创建的一个库,用于帮助处理Silverlight和WP7。

    使用Restful Silverlight从Twitter检索tweets的示例:

    
    //silverlight 4 usage
    List<string> tweets = new List<string>();
    var baseUri = "http://search.twitter.com/";
    
    //new up asyncdelegation
    var restFacilitator = new RestFacilitator();
    var restService = new RestService(restFacilitator, baseUri);
    var asyncDelegation = new AsyncDelegation(restFacilitator, restService, baseUri);
    
    //tell async delegation to perform an HTTP/GET against a URI and return a dynamic type
    asyncDelegation.Get<dynamic>(new { url = "search.json", q = "#haiku" })
        //when the HTTP/GET is performed, execute the following lambda against the result set.
        .WhenFinished(
        result => 
        {
            textBlockTweets.Text = "";
            //the json object returned by twitter contains a enumerable collection called results
            tweets = (result.results as IEnumerable).Select(s => s.text as string).ToList();
            foreach (string tweet in tweets)
            {
                 textBlockTweets.Text += 
                 HttpUtility.HtmlDecode(tweet) + 
                 Environment.NewLine + 
                 Environment.NewLine;
            }
        });
    
    asyncDelegation.Go();
    
    //wp7 usage
    var baseUri = "http://search.twitter.com/";
    var restFacilitator = new RestFacilitator();
    var restService = new RestService(restFacilitator, baseUri);
    var asyncDelegation = new AsyncDelegation(restFacilitator, restService, baseUri);
    
    asyncDelegation.Get<Dictionary<string, object>>(new { url = "search.json", q = "#haiku" })
                   .WhenFinished(
                   result =>
                   {
                       List<string> tweets = new List();
                       textBlockTweets.Text = "";
                       foreach (var tweetObject in result["results"].ToDictionaryArray())
                       {
                           textBlockTweets.Text +=
                               HttpUtility.HtmlDecode(tweetObject["text"].ToString()) + 
                               Environment.NewLine + 
                               Environment.NewLine;
                       }
                   });
    
    asyncDelegation.Go();