Creating web service connector automation

  • Thread starter Thread starter H?kan Bengtsson via .NET 247
  • Start date Start date
H

H?kan Bengtsson via .NET 247

I have written an automation class that connects to an URL, and downloads the content into an ordinary string variable.

But when I run my method I get an error saying:
Request for the permission of type System.Web.Permission, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.

My method looks like this:
WebClient webClient = new WebClient();
new WebPermission(NetworkAccess.Accept|NetworkAccess.Connect, "*").Assert();
StreamReader streamReader = new StreamReader(webClient.OpenRead(urlString));
String content = streamReader.ReadToEnd();

Does anyone know whats wrong??
 
H?kan Bengtsson via .NET 247 said:
I have written an automation class that connects to an URL, and downloads
the content into an ordinary string variable.
But when I run my method I get an error saying:
Request for the permission of type System.Web.Permission, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.
My method looks like this:
WebClient webClient = new WebClient();
new WebPermission(NetworkAccess.Accept|NetworkAccess.Connect,
"*").Assert();

http://msdn.microsoft.com/library/d...tml/frlrfsystemnetwebpermissionclasstopic.asp

"WebPermission provides a set of methods and properties to control access to
Internet resources. You can use a WebPermission to provide either restricted
or unrestricted access to your resource, based on the PermissionState set
when the WebPermission is created."

I think your problem is more of Credentials, try to add:
webClient.Credentials=System.Net.CredentialCache.DefaultCredentials;
 
Back
Top