Can I create a web service that streams a pdf for download

£可爱£侵袭症+ 提交于 2020-01-02 08:25:29

问题


I don't have much experience with web services, but I think I have a problem for which a web service would work great.

My company has just purchased a .net version of Cete Pdf Merger (great product btw). We use both .Net & asp code and will likely use java in the future as well.

The scenario is that one technology (asp, java, .net) would have a list of raw data such as an array of field names & values. This data would be posted to the web service that would then open a given pdf, match pdf form fields to the field names array, grab the corresponding value, populate it on the pdf, and then stream the pdf back to the user to download.

Does this seem feasible? Any gotcha's I might run into that you know of? Any preferred method of doing (Web Services, WCF, ???)


回答1:


Short answer: WCF

Longer answer is: you seem to be making a distinction between WCF and "web services". Perhaps you're thinking of the old ".asmx" web services. Microsoft now considers them to be "legacy software", and suggests you use WCF for all new web service development.




回答2:


If you're going to use web services with .NET, I recommend using WCF (Windows Communication Foundation).




回答3:


WCF (MSDN) is a good choice, but you if you would like to provide a user interface (such as an HTML form to type in the field values), you could use a regular web form and post to a page with HTTP, returning the PDF output by streaming the response with the appropriate MIME-type.




回答4:


This sounds like a great idea. You could use an .asmx web service (others might look down on .asmx).

Suggest creating a webmethod like so:

(this example is rough around the edges, but it's just to describe the general idea)

[WebMethod]
public void CreatePdfIncomeTax(IncomeTaxForm itf)
{
    // integrate with Cete Pdf Merger 
    string fileName = SomePdfMerging(itf);

    Response.ContentType = "application/pdf";
    Response.AddHeader("Content-Disposition", "inline; filename=foo.pdf");
    Response.WriteFile(path);
    Response.Flush();
    Response.End();
}

...
// a class that the caller would populate as param to the webmethod
public class IncomeTaxForm 
{
   public string FirstName {get;set;}
   public string AddressLine1 {get;set;}
   ...
}



回答5:


I've done pretty much that exact thing but using Aspose as the PDF component. We used an .asmx web service and not WFC which is what I wanted. I would certainly agree with everyone else that say that WCF is the way to go. I know that I would have preferred that, but the decision was unfortunately not mine to make.



来源:https://stackoverflow.com/questions/3525595/can-i-create-a-web-service-that-streams-a-pdf-for-download

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!