0

Trying to transfer a byte array to an ASP.NET 2.0 app in a light-weight manner without using SOAP. I decided to use a generic HTTP handler (.ashx) that interprets the HTTP request body as a Base64 string, decoding it to a byte array and saving to disk.

<%@ 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;
        }
    }
}

The client application (an iOS app in my case) will simply have to encode the bytes as Base64 and post them to the URL of this generic handler (ashx).

I imagine there is a better, more orthodox way to do this. Any ideas are appreciated!

2
  • Why bother with Base64 in the first place? Commented Feb 13, 2013 at 20:38
  • Hi Leppie. I was suggesting Base64 as a way to encode the bytes of the PDF file being transferred in the request body. As I understand it (and I could be wrong), if you want to transfer binary data over HTTP, you have to encode it as a string, and base64 appears to be the popular choice (i.e. .NET web services expect base64 in the SOAP message for byte array arguments). Perhaps a better way exists? Commented Feb 14, 2013 at 6:15

1 Answer 1

1

The thing that comes to mind is POST & GET Requests handled through classes like the HttpWebResponse class. http://msdn.microsoft.com/en-us/library/system.net.httpwebresponse%28v=vs.71%29.aspxx You can have your iOS app try to POST to the ASP.NET app, which is then set up to receive the POST and parse it for your byte array, which you'd include. More, or less, this is how some data was sent across the internet before SOAP.. all SOAP is is a schema for these types of requests.

Sign up to request clarification or add additional context in comments.

1 Comment

and this has nothing to do with base64 fyi, it's all html or xml at this point.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.