[英]How can I migrate this to Web Service
真诚的感谢您的耐心和谅解。
下面的代码通过提供一个框和一个按钮来工作。
该框包含一个url,按钮仅显示“转换”。
如果单击转换按钮,它将打开URL的内容并将其转换为pdf。
这很好。
不幸的是,他们希望将其翻译为Web服务,以便其他应用程序可以通过提供2个输入参数,URL和文档名称来使用它执行类似的任务。
我看了几个创建和使用Web服务的示例,尽管它们看起来很简单,但是编写此代码的方式使其很难翻译。
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();
}
}
如果您能帮助您,我将不胜感激。
Web服务的最基本形式是使用HTTP处理程序 :
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; }
}
}
然后: http://example.com/HtmlToPdfHandler.ashx?url=someurl&name=some_doc_name
: http://example.com/HtmlToPdfHandler.ashx?url=someurl&name=some_doc_name
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.