0
votes

I am trying to get a simple WebClient call working from Silverlight to youtube. I lifted the code from the Microsoft Silverlight site.

Here is the code:

private void SearchTrack_Click(object sender, RoutedEventArgs e) { Uri serviceUri = new Uri("https://www.googleapis.com/youtube/v3/search?part=id%2Csnippet&q=sara+smile&key=AAAAAAAAAAAAAAA"); WebClient downloader = new WebClient(); downloader.OpenReadCompleted += new OpenReadCompletedEventHandler(downloader_OpenReadCompleted); downloader.OpenReadAsync(serviceUri); }

    void downloader_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
    {
        if (e.Error == null)
        {
            Stream responseStream = e.Result;

            // Continue working with responseStream here...
        }
    }

The call fails with the following error:

[System.Security.SecurityException] = {System.Security.SecurityException ---> System.Security.SecurityException: Security error. at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClassa.

If I just hit the URL from my browser the JSON is returned without an issue.

I am running the application from VS/Cassini so I don't think it is the FIle system problem identified at http://blogs.msdn.com/b/silverlightws/archive/2008/03/30/some-tips-on-cross-domain-calls.aspx.

Any help would be greatly appreciated.

Barry

1

1 Answers

1
votes

Here it's said, that it's not possible so easy to interract with google apis from silverlight because of corssdomain access restrictions. You need to add some intermidiate WCF-service, through which Your SL-app will communicate with youtube api.