如何在WCF服务中使用crystal报表

时间:2016-03-30 07:26:26

标签: wcf crystal-reports-2010

我正在研究WCF Web服务和SQL Server 2012.我遇到了下面提到WCF服务的问题,即Print_Invoice在服务器IIS上发布后无法正常工作,但它可以在本地运行成功请问如何我可以解决这个问题。

[WebMethod]
     [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
     public string Print_Invoice(int Duty_Slip_Id)
     {
         try
         {
             List<Common.DTO.InvoiceDTO>data=new List<InvoiceDTO>();
             ReportDocument rd = new ReportDocument();
             using (T_FleetEntities e = new T_FleetEntities())
             {
                 var v = e.Print_Invoice(Duty_Slip_Id);
                 if (v != null)
                 {
                     v.ToList().ForEach(o => data.Add(new Common.DTO.InvoiceDTO()
                     {
                        PNR_No = o.PRN_NO == (object)DBNull.Value ? string.Empty : (string)o.PRN_NO,
                         Inv_Date = Convert.ToString(o.Inv_Date.ToString() == (object)DBNull.Value ? string.Empty : o.Inv_Date.ToString()),
                         Date_In = Convert.ToString(o.Date_In.ToString() == (object)DBNull.Value ? string.Empty : o.Date_In.ToString()),
                         Date_Out = Convert.ToString(o.Date_Out.ToString() == (object)DBNull.Value ? string.Empty : o.Date_Out.ToString()),
                         Time_Out = Convert.ToString(o.Time_Out.ToString() == (object)DBNull.Value ? string.Empty : o.Time_Out.ToString()),
                         Tot_Days = Convert.ToString(o.Tot_Days.ToString() == (object)DBNull.Value ? string.Empty : o.Tot_Days.ToString()),
                         Time_In = Convert.ToString(o.Time_In.ToString() == (object)DBNull.Value ? string.Empty : o.Time_In.ToString()),
                         Km_In = Convert.ToString(o.Km_In.ToString() == (object)DBNull.Value ? string.Empty : o.Km_In.ToString()),
                         Km_Out = Convert.ToString(o.Km_Out.ToString() == (object)DBNull.Value ? string.Empty : o.Km_Out.ToString()),
                         Tot_Hrs = Convert.ToString(o.Tot_Hrs.ToString() == (object)DBNull.Value ? string.Empty : o.Tot_Hrs.ToString()),
                         Tot_Km = Convert.ToString(o.Tot_Km.ToString() == (object)DBNull.Value ? string.Empty : o.Tot_Km.ToString()),
                         Extra_Hr_Amt = Convert.ToString(o.Extra_Hr_Amt.ToString() == (object)DBNull.Value ? string.Empty : o.Extra_Hr_Amt.ToString()),
                         Extra_Km_Amt = Convert.ToString(o.Extra_Km_Amt.ToString() == (object)DBNull.Value ? string.Empty : o.Extra_Km_Amt.ToString()),
                         Night_Allow = Convert.ToString(o.Night_Allow.ToString() == (object)DBNull.Value ? string.Empty : o.Night_Allow.ToString()),
                         Out_Stn_Allow = Convert.ToString(o.Out_Stn_Allow.ToString() == (object)DBNull.Value ? string.Empty : o.Out_Stn_Allow.ToString()),
                         Pkg_Id = Convert.ToString(o.Pkg_Id.ToString() == (object)DBNull.Value ? string.Empty : o.Pkg_Id.ToString()),
                         Rate = Convert.ToString(o.Basic_Rate.ToString() == (object)DBNull.Value ? string.Empty : o.Basic_Rate.ToString()),
                         //Comp_Id = Convert.ToString(o.com.ToString() == (object)DBNull.Value ? string.Empty : o.Comp_Id.ToString()),
                         Extra_Hr = Convert.ToString(o.Extra_Hr.ToString() == (object)DBNull.Value ? string.Empty : o.Extra_Hr.ToString()),
                         Extra_Km = Convert.ToString(o.Extra_Km.ToString() == (object)DBNull.Value ? string.Empty : o.Extra_Km.ToString()),
                         //F_Cat_Id = Convert.ToString(o.F_Cat_Id.ToString() == (object)DBNull.Value ? string.Empty : o.F_Cat_Id.ToString()),
                         //F_Type_Id = Convert.ToString(o.F_Type_Id.ToString() == (object)DBNull.Value ? string.Empty : o.F_Type_Id.ToString()),
                         //Feedback = Convert.ToString(o.Feedback.ToString() == (object)DBNull.Value ? string.Empty : o.Feedback.ToString()),
                         Gross_Amt = Convert.ToString(o.Gross_Amt.ToString() == (object)DBNull.Value ? string.Empty : o.Gross_Amt.ToString()),
                         Inter_State_Tax = Convert.ToString(o.Inter_State_Tax.ToString() == (object)DBNull.Value ? string.Empty : o.Inter_State_Tax.ToString()),
                         //Inv_Status = Convert.ToString(o.Inv_Status.ToString() == (object)DBNull.Value ? string.Empty : o.Inv_Status.ToString()),
                         Other_Rec = Convert.ToString(o.Other_Rec.ToString() == (object)DBNull.Value ? string.Empty : o.Other_Rec.ToString()),
                         Parking = Convert.ToString(o.Parking.ToString() == (object)DBNull.Value ? string.Empty : o.Parking.ToString()),
                         Serv_Tax_Amt = Convert.ToString(o.Serv_Tax_Amt.ToString() == (object)DBNull.Value ? string.Empty : o.Serv_Tax_Amt.ToString()),
                         Toll = Convert.ToString(o.Toll.ToString() == (object)DBNull.Value ? string.Empty : o.Toll.ToString()),
                         Total_Amt = Convert.ToString(o.Total_Amt.ToString() == (object)DBNull.Value ? string.Empty : o.Total_Amt.ToString()),
                         Comp_Nm = Convert.ToString(o.Comp_Nm.ToString() == (object)DBNull.Value ? string.Empty : o.Comp_Nm.ToString()),
                         Company_Email = Convert.ToString(o.Company_Email.ToString() == (object)DBNull.Value ? string.Empty : o.Company_Email.ToString()),
                         Rep_Guest = Convert.ToString(o.Rep_Guest.ToString() == (object)DBNull.Value ? string.Empty : o.Rep_Guest.ToString()),
                         Company_Addr = Convert.ToString(o.Company_Addr.ToString() == (object)DBNull.Value ? string.Empty : o.Company_Addr.ToString()),
                         Company_Nm = Convert.ToString(o.Company_Nm.ToString() == (object)DBNull.Value ? string.Empty : o.Company_Nm.ToString())
                      }));
                }
              string strReportPath;
             strReportPath =HttpContext.Current.Server.MapPath("PrintInvoice.rpt");
             rd.Load(Path.Combine(strReportPath));
             rd.SetDataSource(data);
             rd.ExportToDisk(ExportFormatType.PortableDocFormat, HttpContext.Current.Server.MapPath("files/Invoice.pdf"));

            //Stream strem  =rd.ExportToStream( CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
            //strem.Seek(0, SeekOrigin.Begin);

            // File(strem, "application/pdf", "files/Invoice.pdf");
         }

             string path = HttpContext.Current.Server.MapPath("files/Invoice.pdf");
             return new JavaScriptSerializer().Serialize(path);

       }
         catch (Exception ex)
         {

             return new JavaScriptSerializer().Serialize(ex);
             throw;

         }

     }

0 个答案:

没有答案