0

I am trying to pass a class with a property having a list to Restful service via Post method using HTTPContent. Here is my Controller Code:

    protected async Task<T> GetOfflineReport<T>(ReportSettings rSettings)
            {

    string postUrl = "http://localhost/Application/ReportingDataService/v1/GetOfflineReport2012";

    JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
    PlatformClient _platform = new PlatformClient();
    T result = default(T);

    using (HttpContent httpContent = new StringContent(jsSerializer.Serialize(rSettings)))
    {
    httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

    using (HttpResponseMessage response = await _platform._HttpClient(Session).PostAsync(postUrl, httpContent))
    {
        if (response.IsSuccessStatusCode)
           result = await response.Content.ReadAsAsync<T>();
    }
  }
  return (result);
}

In the above controller method,"ReportSettings" class is as follows:

   [DataContract]
        public class ReportSettings
        {

            [DataMember]
            public string ReportName
            {
                get;
                set;
            }

            [DataMember]
            public string ReportPath
            {
                get;
                set;
            }

            [DataMember]
            public ReportFormat ReportFormat
            {
                get;
                set;
            }

            [DataMember]
            public List<ReportParams> Parameters
            {
                get;
                set;
            }
    }

When I pass the "reportSettings" param as null it is going to service methods. But when the "reportSettings" passing with parameter list it is not hitting service method.

The service method is as follows:

        [WebInvoke(Method = "POST", UriTemplate = "GetOfflineReport2012")]
        [OperationContract]
        IEnumerable<byte> GetOfflineReport2012(ReportSettings reportSettings);

public IEnumerable<byte> GetOfflineReport2012(ReportSettings reportSettings)
        {

              try
                {
                    var dp = _mDbFactory.GetReportingDataProvider();
                    var result = dp.GetOfflineReport2012(reportSettings);
                    return result;
                }
                catch (Exception ex)
                {
                    throw _convertToWebFaultException(ex);
                }

        }

Could you please help me in resolving this issue. How can i pass the values of the reportsettings to the service. I am not receiving any exception,but it is not hitting the service.

AMDI
  • 895
  • 2
  • 17
  • 40

1 Answers1

0

I got the issue resolved. I am passing a null value for parameter.

AMDI
  • 895
  • 2
  • 17
  • 40