简体   繁体   中英

How to upload large file with WCF in MonoDroid

I'm trying to implement WCF into MonoDroid. I think there's no big difference between it and MonoTouch on this issue. And after researching, I counldn't find the supoort for anyother WCF binding mode except BasicHttpBinding.

Honestly I'm not good that WCF at all, so I just tried ways randomly. I can get messages from server with string and byte[] and so on, but when i wanted to upload large data eg. image or audio, the uploaded message which includes big byte[] must be limited under 8192bytes. That causes my uploading into failure.

Now what I can do is to convert the big byte[] into Base64String and split it into 8000bytes pieces, and execute a bunch of commands like UploadAsyn(orderNumber, uploadStringBlock), and reform them up again in server with the orderNumber. and convert back to bytes from Base64string. Very busy and silly!

Otherwise I must think other way to solve large file uploading from mobile phone.

And it's really a big pity and problem not to make all actions achieved totally inside WCF coding.

Hope Mono improve it. and if any help welcome and appreciated.

Your best bet is to not use WCF to upload the data, but instead use a plain HTTP transfer. Use WCF to securely obtain an upload token which could be just a url that encodes both the address where you can perform an HTTP POST and the parameters to associate the POST with the user/state that you are uploading.

For example, your WCF request could do this:

string GetTokenForUpload ()
{
    var uuid = new UUID ();
    db.Insert (key: uuid, for: "upload", login: user.Credentials);
    return base_url + "?id=" + uuid; 
}

Then on your POST handler for a regular ASHX handler, you can do something like:

PostRequest (HttpRequest req, QueryString qstring)
{
    id = qstring ["id"];
    if (!db.Lookup (id, out userCredentials))
        error ();
    // accept post for the user.
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM