jason
jason

Reputation: 2259

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 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, ???)

Upvotes: 3

Views: 5059

Answers (5)

Henric
Henric

Reputation: 1410

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.

Upvotes: 0

p.campbell
p.campbell

Reputation: 100587

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;}
   ...
}

Upvotes: 1

jscharf
jscharf

Reputation: 5899

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.

Upvotes: 1

John Saunders
John Saunders

Reputation: 161781

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.

Upvotes: 2

Bernard
Bernard

Reputation: 7961

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

Upvotes: 1

Related Questions