我正在尝试使用Ajax调用
上传3个单独的图像文件和WCF服务单张图片上传工作正常
[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, UriTemplate = "Saveshot?accesstoken={accesstoken}¬ificationid={notificationid}&userid={userid}&dtype={dtype}", ResponseFormat = WebMessageFormat.Json)]
StatusVO Saveshot(Stream data1, string accesstoken, string notificationid, string userid, string dtype);
但不适用于3图像上传其投掷错误
合同'IService'中的'Saveshot'操作有多个请求体参数,其中一个是Stream。当Stream是一个参数时,正文中不能有其他参数
[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, UriTemplate = "Savshot?accesstoken={accesstoken}¬ificationid={notificationid}&userid={userid}&dtype={dtype}", ResponseFormat = WebMessageFormat.Json)]
StatusVO Saveshot(Stream data1, Stream data2, Stream data3, string accesstoken, string notificationid, string userid, string dtype);
Ajax Call
function upload() {
var fd1 = new FormData();
fd1.append('image', document.getElementById('first').files[0]);
var fd2 = new FormData();
fd2.append('image', document.getElementById('sec').files[0]);;
var fd3 = new FormData();
fd3.append('image', document.getElementById('third').files[0]);;
var url = "http://localhost:1187/Iservice.svc/Saveshot?accesstoken=63868f4cf62ae736818da31f32be8c6c¬ificationid=5&userid=1&dtype=and";
$.ajax({
url: url,
data: JSON.stringify({
'data1': fd1, 'data2': fd2, 'data3': fd3
}),
processData: false,
contentType: false,
type: 'POST',
success: function (chat) {
alert(chat.status);
},
error: function (jqXHR, textStatus, errorThrown) {
alert('failed');
}
});
}
我怎样才能实现它? 或者还有其他方法可以实现吗?
提前感谢您的回复!