2011-12-12 60 views
2

我試圖從寫在報表的自定義代碼中的函數訪問REST服務。我不想將該代碼移入單獨的程序集中,因此問題出在自定義代碼的周圍,請不要發送給定製程序集。SSRS - 自定義代碼

下面的代碼:

Public Shared Function GetData(ByVal id As String) As String 
    Dim strURL As String = ("http://..." & id) 
    Dim webRequest As System.Net.HttpWebRequest = DirectCast(System.Net.WebRequest.Create(strURL), System.Net.HttpWebRequest) 
     webRequest.Method = "Get" 
     Dim webResponse As System.Net.HttpWebResponse = DirectCast(webRequest.GetResponse, System.Net.HttpWebResponse) 
     Dim rdr As New System.IO.StreamReader(webResponse.GetResponseStream) 
     Return rdr.ReadToEnd 
End Function 

當我使用它,我收到錯誤消息:

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& stackMark, Boolean isPermSet) 
at System.Security.CodeAccessPermission.Demand() 
at System.Net.HttpWebRequest..ctor(Uri uri, ServicePoint servicePoint) 
at System.Net.HttpRequestCreator.Create(Uri Uri) 
at System.Net.WebRequest.Create(Uri requestUri, Boolean useUriBase) 
at System.Net.WebRequest.Create(String requestUriString) 
at ReportExprHostImpl.CustomCodeProxy.GetData(String what, String id, String defaultValue) 
The action that failed was: 
Demand 
The type of the first permission that failed was: 
System.Net.WebPermission 
The Zone of the assembly that failed was: 
MyComputer 

而且我想我可能有System.IO未來的問題了。

我在CAS上看了一眼,我完全模糊不清,我不知道我必須更改哪個策略文件,我必須更改哪些代碼組以及如何更改。 我的理解是,這是用於自定義代碼(在的rssrvpolicy.config)代碼組:

<CodeGroup 
    class="UnionCodeGroup" 
    version="1" 
    PermissionSetName="Execute" 
    Name="Report_Expressions_Default_Permissions" 
    Description="This code group grants default permissions for code in report expressions and Code element.> 

         <IMembershipCondition 
           class="StrongNameMembershipCondition" 
           version="1" 
           PublicKeyBlob="002400...CAEDDA2" 
         /> 
</CodeGroup> 

而只是設定PermissionSetName到Fulltrust不作任何改變。

回答

0

您應該在代碼組中嘗試PermissionSetName =「FULLTRUST」。

1

對於任何遇到此問題的人(事實發生一年半後),如果您在嘗試從BIDS查看報告時收到此異常,則需要更新Visual Studio的PrivateAssemblies中的RSPreviewPolicy.config文件目錄。

有三個安全策略文件需要修改以便像這樣使用(表達式或自定義程序集中的自定義代碼)。可以找到詳細的註釋(包括對放置新的CodeGroup元素的位置非常重要的注意事項!!)在MSDN頁面上(截至今天)「Using Reporting Services Security Policy Files」。安全配置文件是報表服務器配置(rssrvpolicy.config),報表管理器配置(rsmgrpolicy.config)和報表設計器配置(RSPreviewPolicy.config)。

對此的一個很好的測試是每次更新一個,並在每次更新後測試所有三個(將報告部署到您的報告服務器實例當然:)。