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:
- public void exportToPDF()
- {
- SqlConnection conn = DbManagement.getConnection();
- conn.Open();
- SqlCommand objCmd = null;
- String sql = "";
- String fileName = "";
-
- DataSet ds1 = new DataSet();
- SqlDataAdapter da;
- DataSet1 ds = new DataSet1();
- CrystalReport1 cr1 = new CrystalReport1();
-
- sql = "SELECT productId " +
- "FROM isProductReport " +
- "WHERE userId = 'dev1'";
- objCmd = new SqlCommand(sql, conn);
- objCmd.ExecuteNonQuery();
-
- da = new SqlDataAdapter(objCmd);
-
- ds1.EnforceConstraints = false;
- da.Fill(ds1, "isProductReport");
-
- cr1.SetDataSource(ds1);
-
- fileName = "reporte de inventario " + DateTime.Now.ToString("dd/MM/yyyy hmmtt");
- cr1.ExportToHttpResponse(ExportFormatType.PortableDocFormat, System.Web.HttpContext.Current.Response, true, fileName);
- }
And this is the code that I normally use to consume web services:
- function exportToPDF()
- {
- var userIdValue = $("#username").val();
-
- $.ajax({
- type: "POST",
- contentType: "application/json",
- url: "http://localhost/Service1.svc/exportToPDF",
- data: JSON.stringify({ userId: userIdValue }),
- dataType: "json",
- success: function (data){
- },
- error: function(result){
- alert(result.status + ' ' + result.StatusText);
- }
- });
- }
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!