0
votes

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?

2

2 Answers

1
votes

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"
1
votes

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;
    }

}