How do I send a stream from a Java applet to an ASP.NET website?

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

I found this link which talks about this issue, but I'm not sure how to actually get the data from the website.

The streams that I will be sending will probably be 1mb-20mb in size and I will need to send additional information like the filename.

I suspect I will be implementing an IHttpHandler to handle POST, but I'm not sure how to approach this.

Anyone ideas?

Thank.

+1


source to share


2 answers


Carl, to respond to your casperOne comment, 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 sending data from Java. Study the docs for your Java infrastructure on how to create a WebService client.

+1


source


Well, if you want to do this in a standard way, you can simulate uploading a file to a site:

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

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



However, this will text-encode the content, which will add overhead to what you download (by about 33%).

I think a better idea would be to expose a web service / method that will accept content using MTOM (I believe there is a library for Java for this).

0


source







All Articles