title: Getting "System.Security.SecurityException" while calling a web api from RDL
body: <p>I need to call a web API from RDL file which is present in the reporting project hosted in SSRS. There is one field in the RDL report which will consume a Web Api response. I have written code in RDL to call that api and get the response using System.net Library but it is getting failed due to some System.Web.permission error.</p>
  
  <p>I have tried to consume the web api using below code written in VB.NET (Target framework version 2.0).I also tried to set <code>trustlevel = full</code> in <em>web.config</em> but that doesn't work and still getting permission denied error.
  I am getting successful web api response on executing the same code with <code>httpWebRequest</code>..etc from console application, but it fails when I try to call from RDL.
   Please let me know how to fix the System.net library permission error.</p>
  
  <p>Getting below error while invoking the above function to consume web api response:</p>
  
  <pre><code>System.Security.SecurityException: Request for the permission of type 'System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
  at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark&amp; stackMark, Boolean isPermSet)
  at System.Security.CodeAccessPermission.Demand()
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>`Public Function STSCall() As String
      Dim url As String = "https://httpbin.org/get?token=8041637103881119"
      Dim cardNumber As String = String.Empty
      Dim httpWebRequest = CType(System.Net.WebRequest.Create(url), System.Net.HttpWebRequest)
      httpWebRequest.Method = "GET"
      httpWebRequest.ContentType = "application/json"
      httpWebRequest.Headers.Add("X-AuthMode", "ServerSimpleAuth")
      httpWebRequest.Headers.Add("X-ServerAuthKey", "STS")
      Dim response = CType(httpWebRequest.GetResponse(), System.Net.HttpWebResponse)
  
      Dim StreamReader As New System.IO.StreamReader(response.GetResponseStream(), System.Text.Encoding.ASCII)
      cardNumber = StreamReader.ToString()
  
      Return cardNumber
      End Function`
  </code></pre>