简体   繁体   English

如何在MonoDroid中使用WCF上传大文件

[英]How to upload large file with WCF in MonoDroid

I'm trying to implement WCF into MonoDroid. 我正在尝试将WCF实现为MonoDroid。 I think there's no big difference between it and MonoTouch on this issue. 我认为它和MonoTouch在这个问题上没有太大区别。 And after researching, I counldn't find the supoort for anyother WCF binding mode except BasicHttpBinding. 经过研究,我找不到除BasicHttpBinding之外的其他WCF绑定模式的替代方法。

Honestly I'm not good that WCF at all, so I just tried ways randomly. 老实说,我对WCF一点都不满意,所以我只是随机尝试了一些方法。 I can get messages from server with string and byte[] and so on, but when i wanted to upload large data eg. 我可以使用字符串和byte []等从服务器获取消息,但是当我想上传大数据时,例如。 image or audio, the uploaded message which includes big byte[] must be limited under 8192bytes. 图片或音频,上传的包含大字节[]的邮件必须限制在8192字节以下。 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. 现在,我可以做的是将big byte []转换为Base64String,并将其拆分为8000bytes,然后执行一堆命令,如UploadAsyn(orderNumber,uploadStringBlock),然后使用orderNumber在服务器中重新进行格式化。 and convert back to bytes from Base64string. 并从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. 不能完全在WCF编码中实现所有动作确实是一个很大的遗憾和问题。

Hope Mono improve it. 希望Mono改善它。 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. 最好的选择是不要使用WCF上载数据,而应使用纯HTTP传输。 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. 使用WCF可以安全地获取一个上传令牌,该令牌可能只是一个URL,该URL编码了可以执行HTTP POST的地址以及将POST与要上传的用户/状态相关联的参数。

For example, your WCF request could do this: 例如,您的WCF请求可以执行以下操作:

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: 然后在常规ASHX处理程序的POST处理程序上,您可以执行以下操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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