Can I create a web service that streams a pdf for download
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 ope开发者_运维问答n 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, ???)
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.
If you're going to use web services with .NET, I recommend using WCF (Windows Communication Foundation).
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.
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;}
...
}
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.
精彩评论