Reputation: 1054
I sincerely beg for your patience and understanding.
The below code works by providing a box and a button.
The box contains a url and the button simply says, Convert.
If you click the convert button, it opens the contents of the url and converts it to pdf.
This works great.
Unfortunately, they want it translated as web service so other apps can use it to perform similar task by providing 2 input params, url and document name.
I have looked at several examples of creating and consuming web services, while they seem fairly simple, the way this code is written makes it extemely difficult to translate.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EO.Pdf;
public partial class HtmlToPdf : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnConvert_Click(object sender, EventArgs e)
{
//Create a PdfDocument object and convert
//the Url into the PdfDocument object
PdfDocument doc = new PdfDocument();
HtmlToPdf.ConvertUrl(txtUrl.Text, doc);
//Setup HttpResponse headers
HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.ClearHeaders();
response.ContentType = "application/pdf";
//Send the PdfDocument to the client
doc.Save(response.OutputStream);
Response.End();
}
}
If you could be kind enough to assist, I am truly grateful.
Upvotes: 0
Views: 154
Reputation: 1039200
The most basic form of a web service is to use an HTTP handler:
public class HtmlToPdfHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string url = context.Request["url"];
string documentName = context.Request["name"];
PdfDocument doc = new PdfDocument();
HtmlToPdf.ConvertUrl(url, doc);
context.Response.ContentType = "application/pdf";
doc.Save(context.Response.OutputStream);
}
public bool IsReusable
{
get { return false; }
}
}
and then: http://example.com/HtmlToPdfHandler.ashx?url=someurl&name=some_doc_name
For more advanced services you might take a look at WCF
or the upcoming Web API
.
Upvotes: 1