C#(036):Reporting Service编程—-访问Web服务(C# (036): Reporting Service Programming — accessing web services)

将报表服务器 Web 服务的引用添加到项目中后,下一步是创建 Web 服务代理类的实例。 然后,您可以通过调用代理类中的方法来访问 Web 服务的方法。

当你的应用程序调用这些方法时,代理类生成的代码Visual Studio处理你的应用程序和 Web 服务之间的通信。

    RS_hatl.ReportingService rs = new RS_hatl.ReportingService();
    //rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
    rs.Credentials = new System.Net.NetworkCredential("administrator", "ATit@2609`", "hzamtek");
    //rs.Url = "http://<Server Name>/reportserver/reportservice2010.asmx";  
    rs.Timeout = -1;
    // Render 参数
    byte[] result = null;
    string reportPath = "/YBB/APTB";
    string format = "pdf";
    string historyID = null;
    string devInfo = @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";
    // 准备报表参数
    RS_hatl.ParameterValue[] parameters = new RS_hatl.ParameterValue[1];
    parameters[0] = new RS_hatl.ParameterValue();
    parameters[0].Name = "AgingTo";
    parameters[0].Value = this.TextBox1.Text;
    RS_hatl.DataSourceCredentials[] credentials = null;
    string showHideToggle = null;
    //输出参数
    string encoding;
    string mimeType;
    RS_hatl.ParameterValue[] reportHistoryParameters = null;
    RS_hatl.Warning[] warnings = null;
    string[] streamIDs = null;
    try
    {
        rs.SessionHeaderValue = new RS_hatl.SessionHeader();
        //呈现报表
        result = rs.Render("/YBB/APTB", format, historyID, devInfo, parameters, credentials, showHideToggle,
            out encoding, out mimeType, out reportHistoryParameters, out warnings, out streamIDs);
        Response.Write("Execution date and time: " + rs.SessionHeaderValue.ExecutionDateTime + "<br>");
    }
    catch (SoapException e)
    {
        Response.Write(e.Detail.OuterXml);
    }
    // Write the contents of the report to an MHTML file.
    try
    {
        string FilePath = rs.SessionHeaderValue.SessionId + "_APTB.pdf";
        FileStream stream = File.Create(Server.MapPath("pdf/") + rs.SessionHeaderValue.SessionId + "_APTB.pdf", result.Length);
        stream.Write(result, 0, result.Length);
        stream.Close();
        this.Label9.Text = "报表文件已经创建:<br><a href=" + "pdf/" + rs.SessionHeaderValue.SessionId + "_APTB.pdf" + "> 查看报表</a><br。";
        this.PrintWithDialog("http://192.168.1.10/FSReports/pdf/" + FilePath);
    }
    catch (Exception e)
    {
        Response.Write(e.Message);
    }
————————

After adding the reference of the report server web service to the project, the next step is to create an instance of the web service proxy class. You can then access the methods of the web service by calling the methods in the proxy class.

When your application calls these methods, the code generated by the proxy class visual studio handles the communication between your application and the web service.

    RS_hatl.ReportingService rs = new RS_hatl.ReportingService();
    //rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
    rs.Credentials = new System.Net.NetworkCredential("administrator", "ATit@2609`", "hzamtek");
    //rs.Url = "http://<Server Name>/reportserver/reportservice2010.asmx";  
    rs.Timeout = -1;
    // Render 参数
    byte[] result = null;
    string reportPath = "/YBB/APTB";
    string format = "pdf";
    string historyID = null;
    string devInfo = @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";
    // 准备报表参数
    RS_hatl.ParameterValue[] parameters = new RS_hatl.ParameterValue[1];
    parameters[0] = new RS_hatl.ParameterValue();
    parameters[0].Name = "AgingTo";
    parameters[0].Value = this.TextBox1.Text;
    RS_hatl.DataSourceCredentials[] credentials = null;
    string showHideToggle = null;
    //输出参数
    string encoding;
    string mimeType;
    RS_hatl.ParameterValue[] reportHistoryParameters = null;
    RS_hatl.Warning[] warnings = null;
    string[] streamIDs = null;
    try
    {
        rs.SessionHeaderValue = new RS_hatl.SessionHeader();
        //呈现报表
        result = rs.Render("/YBB/APTB", format, historyID, devInfo, parameters, credentials, showHideToggle,
            out encoding, out mimeType, out reportHistoryParameters, out warnings, out streamIDs);
        Response.Write("Execution date and time: " + rs.SessionHeaderValue.ExecutionDateTime + "<br>");
    }
    catch (SoapException e)
    {
        Response.Write(e.Detail.OuterXml);
    }
    // Write the contents of the report to an MHTML file.
    try
    {
        string FilePath = rs.SessionHeaderValue.SessionId + "_APTB.pdf";
        FileStream stream = File.Create(Server.MapPath("pdf/") + rs.SessionHeaderValue.SessionId + "_APTB.pdf", result.Length);
        stream.Write(result, 0, result.Length);
        stream.Close();
        this.Label9.Text = "报表文件已经创建:<br><a href=" + "pdf/" + rs.SessionHeaderValue.SessionId + "_APTB.pdf" + "> 查看报表</a><br。";
        this.PrintWithDialog("http://192.168.1.10/FSReports/pdf/" + FilePath);
    }
    catch (Exception e)
    {
        Response.Write(e.Message);
    }