Skip to main content
Home Forums General Silverlight Getting Started WebClient
5 replies. Latest Post by Mog Liang - MSFT on July 8, 2009.
(0)
skywalke...
Member
0 points
3 Posts
07-04-2009 4:56 AM |
Dera All,
Follow code are copied from MSDNhttp://msdn.microsoft.com/zh-tw/library/cc645034(VS.95).aspxI know the basic programming and XAML,so I don't key in the detail of the implement of the following code.I use Visual Studio 2008 Express Edition to implement this project.But it can't run.Does following code have any problem?Or it is just my problem.
<TextBlock x:Name ="OutputTextBlock" Canvas.Top ="10" TextWrapping="Wrap"/>
Imports System.IOImports System.Xml.LinqImports System.Net
Dim wc As WebClient = New WebClient()AddHandler wc.OpenReadCompleted, AddressOf wc_OpenReadCompletedwc.OpenReadAsync(New Uri(uriString))
Private Sub wc_OpenReadCompleted(ByVal sender As Object, ByVal e As OpenReadCompletedEventArgs) If e.Error IsNot Nothing Then OutputTextBlock.Text = e.Error.Message Return End If Using s As Stream = e.Result Dim doc As XDocument = XDocument.Load(s) OutputTextBlock.Text = doc.ToString(SaveOptions.OmitDuplicateNamespaces) End UsingEnd Sub
jay nana...
Contributor
3388 points
624 Posts
07-04-2009 4:58 AM |
can you tell what kind of error you are getting?
07-04-2009 8:59 AM |
System.Net.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)System.Net.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result)System.Net.WebClient.OpenReadAsyncCallback(IAsyncResult result)
Above Error from the following code:If e.Error IsNot Nothing Then OutputTextBlock.Text = e.Error.Message & e.Error.StackTrace ReturnEnd Ife.Error.Message is space or null.
07-04-2009 9:33 AM |
uriString variable should contain valid value like this one:
http://feeds.feedburner.com/CommunitySilverlightContent
07-05-2009 12:40 AM |
I put a xml file in my skydrive web harddisk. And I set the url of the xml file for uriString.
I can see the xml file content in design time in the visual studio 2008 express edition. But I can't see the xml file content in run time in IE. And I got above error message.
Mog Lian...
Star
14812 points
1,417 Posts
07-08-2009 2:20 AM |
Hi Skywalker,
From your description, I understand that you encountered the problem when using WebClient to download xml file from SkyDrive. If I misunderstood you, please correct me.
Due to security reason, there is some restriction for silverlight accessing cross-domain resource.
From the error message you provided, I inferred that the target server doesn't provide policy file or policy doesn't allow your access.
To solve the problem, we have several choices
<access-policy> <cross-domain-access> <policy> <allow-from http-request-headers="*"> <domain uri="*"/> </allow-from> <grant-to> <resource path="/" include-subpaths="true"/> </grant-to> </policy> </cross-domain-access> </access-policy>
For more information about Network security access restriction in silverlight, please check this article
http://msdn.microsoft.com/en-us/library/cc645032(VS.96).aspx
Thanks,