Export words across webservice

This is my service to export word to browser client .when client call webservice.

[WebMethod]
public void XemDonDangKy(string MaDonVi, string HoSoID, string DichVuCongID, string KhachHangID, HttpResponse Response)
{
    string DonViID = ConfigurationManager.AppSettings[MaDonVi + "ID"].ToString();
    //Instantiate an instance of license and set the license file through its path
    License license = new License();
    string licenseAsposePath = ConfigurationManager.AppSettings["licenseAsposePath"];
    license.SetLicense(licenseAsposePath);
    //Open template
    string sharePointListPath = ConfigurationManager.AppSettings["uploadedFilePath"];
    string filename = GetTemplateFileName(MaDonVi, DonViID, DichVuCongID).Tables[0].Rows[0]["TemplateName"].ToString();
    string url = sharePointListPath + filename;
    //Create document
    Document doc = new Document(url);
    DataSet ds = new DataSet();
    //thong tin khach hang
    DataTable dt = GetThongTinhKHachHangMerg(ConfigurationManager.AppSettings["HCM"], KhachHangID).Tables[0];
    dt.TableName = "KH";
    ds.Tables.Add(dt.Copy());
    //thong tin ho so
    DataTable dt2 = GetThongTinHoSoMerg(MaDonVi, HoSoID, DichVuCongID).Tables[0];
    dt2.TableName = "HS";
    ds.Tables.Add(dt2.Copy());
    // Fill the fields in the document with user data.
    doc.MailMerge.ExecuteWithRegions(ds);
    // Send the document in Word format to the client browser with an option to save to disk or open inside the current browser.
    doc.Save("InBieNhan_" + DateTime.Now.ToString("dd_MM_yyyy_hh_mm_ss") + ".doc", Aspose.Words.SaveFormat.Doc, Aspose.Words.SaveType.OpenInWord, Response);
}

and i get error like that

System.Web.HttpResponse cannot be serialized because it does not have a parameterless constructor

Anyone help me? Thanks a lot

Hi,

Thanks for your inquiry and sorry for the delayed response. I think, you can resolve this problem after reading the discussion in the following page:
http://stackoverflow.com/questions/1723919/system-web-httpcontext-cannot-be-serialized-because-it-does-not-have-a-paramete

Please let me know if I can be of any further assistance.

Best Regards,

Hi,

It is impossible to use Response in the WebMethod. If you would like to return file form WebMethod then you should return file bytes. Here are steps you should follow.

  1. Create web service and create method (for example GetDocument). This method will create or open the document and return its byte array. Please see the following code:
[WebMethod]
public byte[] GetDocument()
{
    //Create or open document
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);
    builder.Write("Hello world");
    //Save document into MemoryStream
    MemoryStream docStrm = new MemoryStream();
    doc.Save(docStrm, SaveFormat.Doc);
    //Get file bytes
    byte[] docBytes = docStrm.GetBuffer();
    return docBytes;
}
  1. Create virtual directory for your Web Service. On my side link to the newly created web service is:
    http://localhost/GetDocumentService/Service.asmx

  2. Create console application (just for testing, it may be any type of application). Add Web Reference to your Web Service. You should insert link to your service and give the name. (I use GetDocumentService name)

  3. Now you can call your WebMethod from your console application. See the following code:

[C#]

static void Main(string[] args)
{
    //Create instance of web service
    GetDocumentService.Service docService = new GetDocumentService.Service();
    //Get document bytes
    byte[] docBytes = docService.GetDocument();
    //Save file
    FileStream docFile = new FileStream(@"C:\Temp\out.doc", FileMode.Create);
    docFile.Write(docBytes, 0, docBytes.Length);
    docFile.Close();
}

I hope, this will help.

Best Regards,