views:

51

answers:

1

I wrote a method to post to Twitter using webclient. Everything works fine when calling the method from a console app.

I migrated the method to Silverlight 4. Here is where the fun begins. After cleaning up the code, switching to an asynchronous method call, and getting rid of the red squiggled underlines, the code now runs inside my SL4 app. The tweets do not, however, actually post to my twitter page.

I wired up an event handler for the "_completed" event. It gets fired. Also wired up an event handler for the "_uploadProgressChanged" event. It never gets fired. Could be upload is too quick?

Any suggestions for troubleshooting this?

Update #2- Correction... the "_completed" event DOES NOT get fired. I also added Fiddler to the mix to watch the traffic. It does not appear the app is transmitting anything. Fiddler does show activity if I post to stackoverflow (so Fiddler is working).

public static void PostTwitterUpdate(string handle, string pwd, string tweet)
{
     WebClient webClient = new WebClient();

     webClient.Credentials = new NetworkCredential(handle, pwd);

     Uri uriString = new Uri("http://twitter.com/statuses/update.xml", UriKind.Absolute);

     try
     {
          // event handlers added tongiht for debugging...
          webClient.UploadProgressChanged += webClient_UploadProgressChanged;
          webClient.UploadStringCompleted += webClient_UploadStringCompleted;

          webClient.UploadStringAsync(uriString, "It's just me testing...");
     }

     catch (Exception ex)
     {
          throw;
     }

}


static void webClient_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
{
     // breakpoint set here for debugging...
}  




static void webClient_UploadProgressChanged(object sender, UploadProgressChangedEventArgs e)
{
     // breakpoint set here for debugging...
}
+1  A: 

This only would work in an elevated trust Out-of-Browser application because the Twitter Cross Domain Policy File at http://twitter.com/crossdomain.xml does not permit the calls for web page based apps. Michael

Michael S. Scherotter