Click here to Skip to main content
15,918,706 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to develop a simple web app to load an xml file from the MetOffice service and use its content to form a url to a rainfall map. I am getting the permission request error when I try to load the xml document with the xml from the service. I have done this and much more on a desktop application to do the same thing and have never had this error. How can I solve it? I am writing it C#, thank you.

C#
private void save_Click(object sender, RoutedEventArgs e)
        {
            XmlDocument capabilities = new XmlDocument();
            capabilities.Load("http://datapoint.metoffice.gov.uk/public/data/layer/wxobs/all/xml/capabilities?key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
            TimeSteps.Items.Clear();

            for (int x = 0; x < capabilities.SelectNodes("//Layer[@displayName='Rainfall']/Service/Times/Time").Count; x++)
            { TimeSteps.Items.Add(capabilities.SelectNodes("//Layer[@displayName='Rainfall']/Service/Times/Time")[x].InnerText); }            
            {
                ImageLayer.Source = new BitmapImage(new Uri("http://datapoint.metoffice.gov.uk/public/data/layer/wxobs/RADAR_UK_Composite_Highres/png?TIME=" + TimeSteps.Items[0].ToString() + "Z&key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"));
                TimeSteps.SelectedIndex = 0;
            }
        }


Error:
SecurityException was unhandled in user code: Request for the permission of type 'System.Net.WebPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
Posted
Updated 15-Oct-13 11:58am
v2
Comments
Bernhard Hiller 16-Oct-13 2:31am    
If you download the xml file to disk, and then load that file, do you get the same error, or a different one, or none at all?
When I try to open the URL in Firefox, I receive an empty document only (well, I do not have your key...). Check that you get a document with contents.
Henry Hunt 16-Oct-13 2:44am    
Nope same error when I save it to the disk and use that instead. Is it something to do with the security rights of the application or code? But this time it is a request for a FileIOPermission not a web one I just noticed.
Bernhard Hiller 16-Oct-13 2:55am    
Need exact information: do you get the error when you request the file for download, or when you try to open the downloaded file?
Henry Hunt 16-Oct-13 3:00am    
In both errors, it is when I load the XmlDocument capabilities with either a local file or a file on the web. So it is when I request it I suppose.

Loading a file from the web: Request for the permission of type 'System.Net.WebPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Loading a local file: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

1 solution

For testing purposes, set your trust level to Full in the web.config. If this works, use this information: http://msdn.microsoft.com/en-us/library/tkscy493(VS.80).aspx to configure the trust level in the proper way.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900