Step 1
Add ASP.Net Web Service in 4.0.
Step 2
For Twitterizer reference use the following procedure:
Step 3
Check the code behind the web service Service1.asmx.cs
  1. public class Service1 : System.Web.Services.WebService
  2. {
  3. string requestToken = string.Empty;
  4. string pin = string.Empty;
  5. string oauth_consumer_key;
  6. string oauth_consumer_secret;
  7. [WebMethod]
  8. public string HelloWorld()
  9. {
  10. return "Hello World";
  11. }
  12. [WebMethod]
  13. public OAuthTokenResponse function1(string x)
  14. {
  15. OAuthTokenResponse reqToken = null;
  16. oauth_consumer_key = "abcdefghijk";
  17. oauth_consumer_secret = "1234567890123213232";
  18. if (HttpContext.Current.Request["oauth_token"] == null)
  19. {
  20. reqToken = OAuthUtility.GetRequestToken(oauth_consumer_key, oauth_consumer_secret, x);
  21. }
  22. return reqToken;
  23. }
  24. [WebMethod]
  25. public bool function2(string requestToken, string pin)
  26. {
  27. oauth_consumer_key = "abcdefghijk";
  28. oauth_consumer_secret = "1234567890123213232";
  29. var tokens = OAuthUtility.GetAccessToken(oauth_consumer_key, oauth_consumer_secret, requestToken, pin);
  30. OAuthTokens accesstoken = new OAuthTokens()
  31. {
  32. AccessToken = tokens.Token,
  33. AccessTokenSecret = tokens.TokenSecret,
  34. ConsumerKey = oauth_consumer_key,
  35. ConsumerSecret = oauth_consumer_secret
  36. };
  37. //~/img/th2.jpg
  38. byte[] photo = File.ReadAllBytes(@"D:\MVC_GROUP_DEAL\WebApplication1\WebService1\th22.jpg");
  39. TwitterResponse<TwitterStatus> response = TwitterStatus.UpdateWithMedia(accesstoken, "img", photo);
  40. if (response.Result == RequestResult.Success)
  41. {
  42. return true;
  43. }
  44. else
  45. {
  46. return false;
  47. }
  48. }
  49. }
Step 4
Add a new project. Create an ASP.Net web application in Framework 3.5. Add a default page. In the code behind add the following code.
  1. using Twitterizer;
  2. using WebApplication1.localhost;
  3. protected void Page_Load(object sender, EventArgs e)
  4. {
  5. Service1 oService1 = new Service1();
  6. if (Request["oauth_token"] == null)
  7. {
  8. WebApplication1.localhost.OAuthTokenResponse oaToken = (WebApplication1.localhost.OAuthTokenResponse)oService1.function1(Request.Url.AbsoluteUri);
  9. HttpContext.Current.Response.Redirect(string.Format("http://twitter.com/oauth/authorize?oauth_token={0}", oaToken.Token));
  10. }
  11. else
  12. {
  13. string requestToken = Request["oauth_token"].ToString();
  14. string pin = Request["oauth_verifier"].ToString();
  15. bool i = oService1.function2(requestToken, pin);
  16. Response.Write("Message Posted ");
  17. }
  18. }
Step 5
It will ask for a Twitterizer reference; for that use the following procedure:
Step 6
Rebuild all and see the output.
message-in-twitter.jpg
message-in-twitter1.jpg