download PDF from web service using json

download PDF from web service using json

Hi, I have a WCF service that creates a report in PDF, it works, since I have a C# app that use it, however I need to use the same method to obtain the same document in my jquery mobile application. This is the method that generates the document:

  1.         public void exportToPDF()
  2.         {
  3.             SqlConnection conn = DbManagement.getConnection();
  4.             conn.Open();
  5.             SqlCommand objCmd = null;
  6.             String sql = "";
  7.             String fileName = "";

  8.             DataSet ds1 = new DataSet();
  9.             SqlDataAdapter da;
  10.             DataSet1 ds = new DataSet1();
  11.             CrystalReport1 cr1 = new CrystalReport1();

  12.             sql = "SELECT productId " +
  13.                     "FROM isProductReport " +
  14.                    "WHERE userId = 'dev1'";
  15.             objCmd = new SqlCommand(sql, conn);
  16.             objCmd.ExecuteNonQuery();

  17.             da = new SqlDataAdapter(objCmd);

  18.             ds1.EnforceConstraints = false;
  19.             da.Fill(ds1, "isProductReport");

  20.             cr1.SetDataSource(ds1);

  21.             fileName = "reporte de inventario " + DateTime.Now.ToString("dd/MM/yyyy hmmtt");
  22.             cr1.ExportToHttpResponse(ExportFormatType.PortableDocFormat, System.Web.HttpContext.Current.Response, true, fileName);
  23.         }

And this is the code that I normally use to consume web services:

  1. function exportToPDF()
  2. {
  3. var userIdValue = $("#username").val();
  4. $.ajax({
  5. type: "POST",
  6. contentType: "application/json",
  7. url: "http://localhost/Service1.svc/exportToPDF",
  8. data: JSON.stringify({ userId: userIdValue }),
  9. dataType: "json",
  10. success: function (data){
  11. },
  12. error: function(result){
  13. alert(result.status + ' ' + result.StatusText);
  14. }
  15. });
  16. }

The method does not return anything since it's void, I'm sure that for this kind of operation, what I'm doing is not correct, but I don't know how to solve this issue, I'm able to read and retrieve any value from the database, but this is completely different. I would appreciate your help, thanks!