tags:

views:

153

answers:

2

I would like to be able to send a stream of binary data to an asp .net website from a java applet hosted in the same website.

I found this link which talks about this issue, but I am unsure how to actually receive the data on the website.

The streams I will be sending will probably be in the order of 1mb-20mb in size and I will need to send additional information, such as a file name.

I suspect I would implement an IHttpHandler to handle a POST, but I'm unsure how to approach this.

Any ideas anyone?

Thanks.

A: 

Well, if you want to do it in a standards-based way, you can mimic uploading a file to the site:

http://www.jguru.com/faq/view.jsp?EID=160

And on the ASP.NET side, you would just access the file through the Files property on the HttpRequest.

However, this will end up text-encoding the contents, which is going to add overhead to what you upload (by about 33%).

I think a better idea would be to expose a web service/method which will accept the contents using MTOM (I believe Java has a library for this).

casperOne
Thanks for the response casperOne, but my problem is how do I actually "accept the contents" in the website?
Carl
+1  A: 

Carl, to answer your comment to casperOne, add a new web service to your ASP.NET site and do something like this...

using System;
using System.IO;
using System.Web.Services;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
    [WebMethod]
    public bool RecieveBytes(byte[] data)
    {
        try
        {
            File.WriteAllBytes("~/uploads/uploadedFile.dat", data);
        }
        catch (Exception ex)
        {
            return false;
        }
        return true;
    }
}

As for submitting the data from Java. Have a look into the docs for your Java framework as to how to create a WebService Client.

Greg B
Thanks Greg. I'll look into that.
Carl