I have a File i want to upload to a Webservice, but it needs additional params, so I create some hidden fields with the associated name:value pairs to get pushed to the server request. The issue though is the definition of the service.
[Error]
Operation 'NewImage' in contract 'IFormServices' has multiple request body parameters, one of which is a Stream. When the Stream is a parameter, there can be no other parameters in the body.
[interface]
[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json)]
string NewImage(Stream data, string server,string datasource, string document, string image_id);
[definition]
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 code]
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();
} );
So i am trying to figure out a way to send up 4 strings + a file to the server.
How would this be done?
edit: put error code at top.