SOAP を使用せずにバイト配列を軽量な方法で ASP.NET 2.0 アプリに転送しようとしています。HTTP 要求本文を Base64 文字列として解釈し、バイト配列にデコードしてディスクに保存する汎用 HTTP ハンドラー (.ashx) を使用することにしました。
<%@ WebHandler Language="C#" Class="PdfPrintService" %>
using System;
using System.Web;
public class PdfPrintService : IHttpHandler {
public void ProcessRequest (HttpContext context) {
string body;
using (System.IO.StreamReader reader =
new System.IO.StreamReader(context.Request.InputStream))
{
body = reader.ReadToEnd();
}
byte[] bytes = System.Convert.FromBase64String(body);
String filePath = System.IO.Path.GetTempFileName() + ".pdf";
System.IO.File.WriteAllBytes(filePath, bytes);
// Print file.
XyzCompany.Printing.PrintUtility.PrintFile(filePath);
}
public bool IsReusable {
get {
return false;
}
}
}
クライアント アプリケーション (私の場合は iOS アプリ) は、バイトを Base64 としてエンコードし、この汎用ハンドラー (ashx) の URL にポストするだけです。
これを行うには、より良い、より正統な方法があると思います。どんなアイデアでも大歓迎です!