我有一个要上传到 Web 服务的文件,但它需要额外的参数,所以我创建了一些带有关联名称的隐藏字段:值对以推送到服务器请求。但问题是服务的定义。
[错误]
合同“IFormServices”中的操作“NewImage”有多个请求主体参数,其中一个是 Stream。当 Stream 为参数时,body 中不能有其他参数。
[界面]
[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json)]
string NewImage(Stream data, string server,string datasource, string document, string image_id);
[定义]
public string NewImage(Stream data, string server, string datasource, string document, string image_id)
{
//this should, similar to others, need a server, datasource, and some sort of document in which to append the images.
WebClient wsb = new WebClient();
string str = "_URL_";
byte[] byte_data = new byte[data.Length];
data.Read(byte_data, 0, byte_data.Length);
byte[] response = wsb.UploadData(str,"POST",byte_data);
string retVal = Convert.ToString(response);
//want to return a JSON.serialized dictionary of: given image_id + id returned from response.
Dictionary<string, object> retDict = new Dictionary<string, object>();
retDict["filename"] = image_id;
retDict["id"] = "";
//return new JavaScriptSerializer().Serialize(json);
return "-1";
}
[javascript代码]
var $form = $("<form />").attr({
method: "POST",
enctype: "multipart/form-data",
target: "image_processing",
action: "webservices/FormServices.svc/NewImage",
id: "push_image_to_server"
} ).appendTo( "body" );
var im_id = $( this ).attr( "image_id" );
$( this ).appendTo( "form#push_image_to_server" );
$( "<input type='hidden' />" ).attr( { name: "server", value: BASE_URL } ).appendTo( $form );
$( "<input type='hidden' />" ).attr( { name: "datasource", value: SELECTED_DATASOURCE } ).appendTo( $form );
$( "<input type='hidden' />" ).attr( { name: "document", value: SELECTED_DOCUMENT } ).appendTo( $form );
$( "<input type='hidden' />" ).attr( { name: "image_id", value: im_id } ).appendTo( $form );
$("iframe#image_processing").bind("load", function (a,b,c) {
console.log("SUCCESS", arguments);
$( "iframe#image_processing" ).unbind( "load", function (a,b,c)
{
console.log( arguments );
_IMAGE_UPLOADS_[a["filename"]] = a["id"];
} );
$( "form#push_image_to_server" ).remove();
} );
所以我试图找出一种方法将 4 个字符串 + 一个文件发送到服务器。
这将如何完成?
编辑:将错误代码放在顶部。