SSRS 报告 Web 服务中报告参数的日期时间格式问题,而不是报告查看器控件

发布于 2024-11-30 11:49:09 字数 2028 浏览 1 评论 0原文

我想使用 C# 通过 SSRS 报告 Web 服务从报告中读取所有参数。但是我在读取 DateTime 参数时遇到问题。 rdl文件中的参数是英国格式,但在C#中变成了美国格式。

编辑:

我尝试使用下面的代码设置区域性,但它仍然不起作用:

 //set it before instantiating ReportingService2010 instance. 
  Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
  Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB"); 

 //set it when reading a date type value
  Console.WriteLine("{0} {1} {2}", dateTime.Year, dateTime.Month, dateTime.Day);
  Console.WriteLine(dateTime.ToString("yyyy-MM-dd"));
 Console.WriteLine(dateTime.ToString("yyyy-MM-dd", new CultureInfo("en-GB", false)));

使用报表查看器控件时,日期格式是正确的。通过报表查看器控件读取参数时,日期值已经正确 (dd/MM/YYYY)。但是,当通过报告 Web 服务读取相同的参数时,相同的值采用另一种格式 (MM/dd/YYYY)。我认为这就是文化设置不起作用的原因。

下面是我的代码:

ReportingService2010 rs = new ReportingService2010();
      rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

      string report = "/SampleReports/Employee Sales Summary";
      bool forRendering = false;
      string historyID = null;
      ParameterValue[] values = null;
      DataSourceCredentials[] credentials = null;
      ItemParameter[] parameters = null;

      try
      {
         parameters = rs.GetItemParameters(report, historyID, forRendering, values, credentials);

         if (parameters != null)
         {
            foreach (ItemParameter rp in parameters)
            {
string value = parameter.DefaultValues.FirstOrDefault(); //it becomes US format here
               Console.WriteLine("Name: {0}",value);
            }
         }
      }

      catch (SoapException e)
      {
         Console.WriteLine(e.Detail.InnerXml.ToString()); 
      }

ReportingService2010.GetItemParameters 方法

访问 SOAP API

有什么想法吗?

I want to use C# to read all parameters from a report via SSRS reporting web service. But I have a problem when reading a DateTime parameter. The parameter in the rdl file is in British format, but it becomes US format in C#.

Edit:

I tried setting the culture by using the code below, but it still does NOT work:

 //set it before instantiating ReportingService2010 instance. 
  Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
  Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB"); 

 //set it when reading a date type value
  Console.WriteLine("{0} {1} {2}", dateTime.Year, dateTime.Month, dateTime.Day);
  Console.WriteLine(dateTime.ToString("yyyy-MM-dd"));
 Console.WriteLine(dateTime.ToString("yyyy-MM-dd", new CultureInfo("en-GB", false)));

The date format is correct when the report viewer control is used. When the parameter is read via the report viewer control, the date value is already correct (dd/MM/YYYY). However, when the same parameter is read via reporting web service, the samevalue is in another format (MM/dd/YYYY). I think this is the reason that setting the culture is not working.

Below is my code:

ReportingService2010 rs = new ReportingService2010();
      rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

      string report = "/SampleReports/Employee Sales Summary";
      bool forRendering = false;
      string historyID = null;
      ParameterValue[] values = null;
      DataSourceCredentials[] credentials = null;
      ItemParameter[] parameters = null;

      try
      {
         parameters = rs.GetItemParameters(report, historyID, forRendering, values, credentials);

         if (parameters != null)
         {
            foreach (ItemParameter rp in parameters)
            {
string value = parameter.DefaultValues.FirstOrDefault(); //it becomes US format here
               Console.WriteLine("Name: {0}",value);
            }
         }
      }

      catch (SoapException e)
      {
         Console.WriteLine(e.Detail.InnerXml.ToString()); 
      }

ReportingService2010.GetItemParameters Method

Accessing the SOAP API

Any idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光与爱终年不遇 2024-12-07 11:49:09

首先,检查报告本身的语言属性。如果这是正确的,请尝试设置 C# 代码的区域性:

Culture="en-GB"

First, check what the language property is in the report itself. If that is correct, try setting the culture of your C# code:

Culture="en-GB"
欢你一世 2024-12-07 11:49:09

我必须在生成的 ReportingService 类旁边创建一个分部类并重写 GetWebRequest 方法,然后将 Accept-Language 标头添加到 Web 请求中。这是一个示例类:

public partial class ReportingService

{

 protected override System.Net.WebRequest GetWebRequest(Uri uri)
    {
        WebRequest request = base.GetWebRequest(uri);

        request.Headers.Add(HttpRequestHeader.AcceptLanguage, CultureInfo.CurrentCulture.Name);

        return request;
    }

}

I have to create a partial class alongside the generated ReportingService class and override the GetWebRequest method, then add an Accept-Language header to the Web request. Here is a sample class:

public partial class ReportingService

{

 protected override System.Net.WebRequest GetWebRequest(Uri uri)
    {
        WebRequest request = base.GetWebRequest(uri);

        request.Headers.Add(HttpRequestHeader.AcceptLanguage, CultureInfo.CurrentCulture.Name);

        return request;
    }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文