0

I am using the SSRS WinForms client control to display reports in an app. User's behind proxies are getting a 407 (proxy authentication) error. How do I specify proxy settings for the request? i.e. proxy server, username & password. I was expecting it to be similar to the HttpRequest and WebProxy.

This is helpful C# Connecting Through Proxy however I need to specify proxy settings on a per SSRS request basis.

Any ideas?

Thanks.

Community
  • 1
  • 1
pmcilreavy
  • 3,076
  • 2
  • 28
  • 37

1 Answers1

1

You can specify the proxy settings by using reporting web services.

  • Add the reporting web reference to your project. The URL of the web service is :

http://servername/ReportServer/ReportExecution2005.asmx

  • In the code calling the web service.

    byte[] report = null;

            //create an instance of the reporting service web reference
            var reportReference = new ReportExecutionService();
    
            <strong>//Set your proxy settings
             reportReference.Proxy = new WebProxy("address:port");
    
    
            //create a credential that will be used to authenticate again the
    

    reporting services var credential = new NetworkCredential("username", "password", "domainName");

            reportReference.Credentials =
    

    credential;

            reportReference.PreAuthenticate =
    

    true;

            //the virtual path to the report
            string virtualPath = "/Folder/ReportName";
    


            //Specify the device info
            string deviceInfo =
                "<DeviceInfo><Toolbar>False</Toolbar><Parameters>False</Parameters><DocMap>True</DocMap><Zoom>100</Zoom></DeviceInfo>";
    
            //Create an array of parameters, for example our report needs 2 parameters
            var parameters = new ParameterValue[2];
    
            //Specify the value for the parameter
            var startDateParameter = new ParameterValue();
            startDateParameter.Name = "StartDate";
            startDateParameter.Value = "01/01/2008";
    
            parameters[0] = startDateParameter;
    
            var endDateParameter = new ParameterValue();
            endDateParameter.Name = "EndDate";
            endDateParameter.Value = "31/12/2008";
    
            parameters[1] = endDateParameter;
    
            //Create variables for the remainder of the parameters
    
            string extension = string.Empty;
    
            ExecutionHeader executionHeader = null;
    
            reportReference.ExecutionHeaderValue =
    

    executionHeader;

            reportReference.LoadReport(virtualPath,
    

    null);

            reportReference.SetExecutionParameters(parameters,
    

    "en-AU");

            try
            {
                //Execute the report
                string[] streamIDs;
                Warning[] warning = null;
                string encoding;
                string mimeType;
                string format = "PDF";
    
    
                <strong>//Execute the report
                report = reportReference.Render(format,
    

    deviceInfo, out extension, out mimeType, out encoding, out warning, out streamIDs);

                using (var fileStream = new FileStream("myReport.PDF", FileMode.Create))
                {
                    fileStream.Write(report, 0,
    

    report.Length);

                    fileStream.Close();
                }
    

    > Process.Start("myReport.pdf");

            }
            catch (SoapException exception)
            {
    


    }

Toan Nguyen
  • 11,263
  • 5
  • 43
  • 59
  • Hi, Thanks for the answer. But I don't want to entirely re-write the SSRS Winforms control. I want to be able to specify the proxy settings for the existing one. – pmcilreavy Feb 22 '11 at 09:55