I already have a webservice for which I pass an image (Base64) and it saves on my server. So far it's working perfectly.
On my screen you have this code:
function salvar() {
var dados = {};
//Utilizar o toDataURL para converter em Base64
var base64 = document.getElementById("myCanvas").toDataURL("image/png");
dados.base64 = base64.substr(base64.indexOf(',') + 1, base64.length);
var WPath = "face1";
$.ajax({
type: 'POST',
//Chamar o webmethod SalvarImagem em webservice.asmx
url: "SalvarImagem.asmx/SalvarImagemX",
contentType: 'application/json; charset=utf-8',
dataType: 'json',
data: JSON.stringify(dados, WPath),
success: function (data) {
alert(data.d);
}
, error: function (xmlHttpRequest, status, err) {
alert("Ocorreu o seguinte erro:" + xmlHttpRequest.responseText)
}
});
}
And my webservice looks like this:
public class SalvarImagem : System.Web.Services.WebService
{
[WebMethod]
public string SalvarImagemX(string base64, string WPath)
{
//MemoryStream com o base64 recebido por parâmetro
using (MemoryStream ms = new MemoryStream(Convert.FromBase64String(base64)))
{
//Criar um novo Bitmap baseado na MemoryStream
using (Bitmap bmp = new Bitmap(ms))
{
//Local onde vamos salvar a imagem (raiz do site + /canvas.png)
//string path = Server.MapPath("/" + WPath + "/canvas.png");
string path = Server.MapPath("/face2/canvas.png");
//Salvar a imagem no formato PNG
bmp.Save(path, ImageFormat.Png);
}
}
return "Imagem foi salva com sucesso";
}
}
}
My problem is that: As I said it works while I only pass a paramenter which is the string DATA. But I need to pass another string containing the folder where the image should be saved ...
When I put the second parameter (WPath) I got to receive the error message below ... Can anyone tell me what's wrong .... ??
The following error occurred:
{"Message": "Invalid web service call, missing value for parameter: \ u0027WPath \ u0027. "," StackTrace ":" at System.Web.Script.Services.WebServiceMethodData.CallMethod (Object target, IDictionary
2 parameters)\r\n at System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary
2 parameters) \ r \ n at System.Web.Script.Services.RestHandler.InvokeMethod (HttpContext context, WebServiceMethodData methodData, IDictionary'2 rawParams) \ r \ n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall (HttpContext context, WebServiceMethodData methodData) "," ExceptionType ":" System.InvalidOperationException "}