我有文件上传和一些输入文本,我想使用 WCF 将值更新到数据库。
到目前为止,我通过字符串数组发送所有输入值,但我不知道如何使用 WCF 将文件上传到服务器
html:
<input id="file" type="file" >
<textarea name="textarea" class="jqte"> </textarea>
...
JavaScript:
$.ajax({
url: "/WebServices/forum.svc/InsertMessage",
type: "POST",
data: JSON.stringify({ currentMessage: currentMessage }),
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) {
}
});
WCF:
[OperationContract]
public void InsertMessage(List<string> currentMessage)
{
return;
}
知道如何解决这个问题吗?
谢谢
巴罗兹
最佳答案
我最近尝试了同样的事情,但失败了。
这种情况最好使用js。 http://www.enfew.com/12-excellent-ajax-upload-plugins/
如果您使用的是现代浏览器,其中许多会使用 ajax,或者如果您使用的是旧浏览器,则返回到 iFrame。因此浏览器兼容性也不是问题。
我自己用过https://code.google.com/p/upload-at-click/ .它使用起来非常简单,并且可以满足您的需要。
关于c# - 发送文件上传到WCF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18081674/