English 中文(简体)
Silverlight 4 webclient authentication - anyone have this working yet?
原标题:

So one of the best parts about the new Silverlight 4 beta is that they finally implemented the big missing feature of the networking stack - Network Credentials!

In the below I have a working request setup, but for some reason I get a "security error" when the request comes back - is this because twitter.com rejected my api call or something that I m missing in code?

It might be good to point out that when I watch this code execute via fiddler it shows that the xml file for cross domain is pulled down successfully, but that is the last request shown by fiddler ...

public void RequestTimelineFromTwitterAPI()
        {
               WebRequest.RegisterPrefix("https://", System.Net.Browser.WebRequestCreator.ClientHttp);

               WebClient myService = new WebClient();
               myService.AllowReadStreamBuffering = true;
               myService.UseDefaultCredentials = false;
               myService.Credentials = new NetworkCredential("username", "password");
               myService.UseDefaultCredentials = false;

               myService.OpenReadCompleted += new OpenReadCompletedEventHandler(TimelineRequestCompleted);
               myService.OpenReadAsync(new Uri("https://twitter.com/statuses/friends_timeline.xml"));
        }

        public void TimelineRequestCompleted(object sender, System.Net.OpenReadCompletedEventArgs e)
        {
            //anytime I query for e.Result I get a security error
        }
最佳回答

I found 2 issues that caused this request to throw the security exception

1) - In this video by Tim Heuer it turns out my VS2010 w/ Silverlight 4 toolkit installation didn t match the final build so I m missing the option that shows up in the "out of browser settings" dialog that provides the checkbox for "Require elevated trust when running outside the browser".

In the video listed above Tim checks this so the Silverlight app can talk to the twitter API

But because my application didn t have this option I had to manually edit the xml file so it looked like the below. You can find this xml under properties in the project folder or inside visual studio directly.

<OutOfBrowserSettings ShortName="TrustedNetworkApp Application" EnableGPUAcceleration="False" ShowInstallMenuItem="True">
  <OutOfBrowserSettings.Blurb>TrustedNetworkApp Application on your desktop; at home, at work or on the go.</OutOfBrowserSettings.Blurb>
  <OutOfBrowserSettings.WindowSettings>
    <WindowSettings Title="TrustedNetworkApp Application" Height="480" Width="640" />
  </OutOfBrowserSettings.WindowSettings>
  <OutOfBrowserSettings.SecuritySettings>
    <SecuritySettings ElevatedPermissions="Required" />
  </OutOfBrowserSettings.SecuritySettings>
  <OutOfBrowserSettings.Icons />
</OutOfBrowserSettings>

Notice the **security settings ElevatedPermissions="Required"

After you save this it s equivalent to checking this as Tim did in the video.

2) - as I was watching that video by Tim I noticed that you have to debug this outside of the browser to get it working. So install the app and run it outside the browser. This app now works.

I ll write a short blog post to summarize my experience with the networking stack under the beta and link to it for anyone interested.

Update

I finally wrote a blog post about my experience building an out of browser twitter client using Silverlight 4 if anyone is interested.

问题回答

暂无回答




相关问题
Silverlight Rich text box control

Our team decided that we need our own custom Rich text box control for Silverlight app we are developing. We looked at existing controls mentioned at A good rich text control for Silverlight but ...

Silverlight ImageBrush not rendering (with Bing Map Control)

I m trying to add an image to a Pushpin instance from the Silverlight Bing Map Control, but I can t seem to get it to render (the pushpin renders fine). This is probably a general WPF question rather ...

Silverlight OpenFileDialog DoEvents equivalent

I m processing large files after they are selected by the user. My code looks like the following: if (FileDialog.ShowDialog() == true) { // process really big file } This freezes up the UI so ...

list of controls with templates in silverlight

Does anyone know where to find a list of controls that you can set the template on in Silverlight? I ve wasted several hours now trying to create control templates only to find that the control doesn ...

Silverlight, Updating the UI during processing

I have a simple silverlight multifile upload application, and i want to provide the user with some feedback, right now its only in a test phase and i dont have the webservice. Somehow i cant get the ...

Silverlight 3 - FindName returns null

This looks a bug to me.. Using Silverlight 3 and i have a user control defined in XAML and trying to access the object during runtime returns a null. <Grid> <common:CommonGridEditPanel x:...

silverlight 3 collection binding

Someone please help me understand why this binding does not work... I have a class called SelectionManager with a property called dates which is populated by a WCF service. The property is an ...

热门标签