Windows Phone 7 and Hammock RESTful Helper Library

by Arra Derderian 4. May 2011 02:53

Looking to get O-Auth working for my Windows Phone 7 application and I started using the Hammock RESTful helper library. It works great for O-Auth because it handles all the messy stuff behind the scenes. You can literally set the appropriate parameters in your methods and Hammock does the rest. Here is a code snapshot:

RestClient client = new RestClient()
{
Authority = "https://query.yahooapis.com/v1",
Credentials = new OAuthCredentials()
{
ConsumerKey = key,
ConsumerSecret = secret,
Token = oauth_token,
TokenSecret = oauth_token_secret,
SignatureMethod = OAuthSignatureMethod.HmacSha1,
ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
Type = OAuthType.ProtectedResource,
Version = "1.0"
}
};

var teamRequest = new RestRequest
{
Path = "/yql?q=select*fromfantasysports.leagues"
};

RestResponse rr = client.Request(teamRequest);

This lets me query my Yahoo! fantasy sports league and return data about my teams in the league. Unfourtunately, Yahoo! has been less than helpful with some of the O-Auth problems I have been having with them. My token keeps getting rejected and their support is terrible. I am waiting on them to get this piece working but in the meantime I have been able to connect my Windows Phone 7 app to my WCF service and use Hammock to make all my asynchronous requests. Because Windows Phone 7 only supports asynchronous requests from your application Hammock is a nice library to properly format and contain all your requests.

One drawback is if you do not use the WebClient class for your web requests then you will have to use the Dispatcher object when updating the UI of your phone app. The WebClient class takes care of this for you but using your own RESTful helper then you need to use Dispatcher in your callback. Here is a code example:

this.Dispatcher.BeginInvoke(() =>

{

//YOUR UI CODE
});

Tags: , ,

Engineering | Technology

Comments

11/7/2011 12:59:49 PM #

Marrakech ici

Yay google is my empress aided me to locate this monumental website ! . “Don’t guide absent active accompanying your helps. It does negative prohibit using your pate.” by Andy Rooney.

Marrakech ici France | Reply

11/13/2011 12:33:32 PM #

Tout Marrakech

Hi, i think that i noticed you visited my blog so i got here to ?go abaft the will?.I’m attempting to discover acts to improve my website!I think its estimable sufficient to manipulate a handful of your thoughts!!

Tout Marrakech France | Reply

11/16/2011 7:16:35 AM #

le secteur immobilier au maroc

I genuinely appreciate looking at on this labyrinth locale , it retains magnificent informs .

le secteur immobilier au maroc France | Reply

11/17/2011 1:15:05 PM #

Lexia3

TV’s original American horror story is taking another step toward returning to primetime

Lexia3 Maldives | Reply

12/8/2011 9:01:54 PM #

cheap HTC phones

Comparing with other website, I conjectured that UK based mobile phone shopping would be very helpful for all because it website cheap mobile phone deals on orange, 02, and Vodafone.

cheap HTC phones United States | Reply

Add comment


(Will show your Gravatar icon)

  Country flag

Click to change captcha
biuquote
  • Comment
  • Preview
Loading