views:

317

answers:

0

Hi

I have created a dll consisting of a class and a static function to fetch attachments from TFS database. Below is the static function

 public static List<string> GetAttachments(int workItemId)
        {
            string tfsReportServerUrl = "http://&lt;&lt;ServerName&gt;&gt;:8080/";

            List<String> files = new List<string>();

            // THE BELOW IS WHAT I THINK SHOULD BE ASSERTED. I HAVE VERY LIMITED KNOWLEDGE IN CODE ACCESS SECURITY.

            //PermissionSet ps = new PermissionSet(PermissionState.None);
            //ps.AddPermission(new WebPermission(PermissionState.Unrestricted));
            //ps.AddPermission(new WebPermission(NetworkAccess.Accept, tfsReportServerUrl));
            //ps.AddPermission(new WebPermission(NetworkAccess.Connect, tfsReportServerUrl));
            //ps.AddPermission(new SecurityPermission(SecurityPermissionFlag.UnmanagedCode | SecurityPermissionFlag.Execution));
            //ps.Assert();

            TeamFoundationServer tfsServer = new TeamFoundationServer(tfsReportServerUrl);
            tfsServer.Authenticate();

            WorkItemStore workItemStore = new WorkItemStore(tfsServer);
            WorkItem workItem = workItemStore.GetWorkItem(workItemId);

            if (workItem != null)
            {
                WebClient request = new WebClient();
                request.Credentials = CredentialCache.DefaultCredentials;

                foreach (Attachment attachment in workItem.Attachments)
                {
                    files.Add(attachment.Name);
                    //Save the attachment to a local file
                    //request.DownloadFile(attachment.Uri, Path.Combine(@"C:\Attachments", attachment.Name));
                }
            }

            return files;
        }

When I try to run the report I get "#Error" on the report. After reading a few articles I know that this error is due to insufficient permissions and while viewing report in "preview" mode SSRS displays "That assembly does not allow partially trusted callers." message.

Based on the below articles

http://www.devx.com/codemag/Article/33656/1954
http://bryantlikes.com/articles/824.aspx

I copied the custom assembly to below locations
C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies
C:\Program Files\Microsoft SQL Server\MSRS10.MSSQLSERVER\Reporting Services\ReportServer\bin locations.

Also added the following codegroup to rssvrpolicy.config file

<CodeGroup class="UnionCodeGroup" version="1" PermissionSetName="FullTrust">
     <IMembershipCondition class="UrlMembershipCondition" version="1" Url="C:\Program Files\Microsoft SQL Server\MSRS10.MSSQLSERVER\Reporting Services\ReportServer\bin\AdvancedTFS.dll" />
</CodeGroup>

But I am not sure which permissions do I need to assert in my custom function (shown above) or how to make this work?

Pls. suggest.

Thanks