使用asmx将图像从android phonegap上传到服务器

我正在尝试从phonegap应用程序(android)上传捕获/库图像,当我调用asmx web服务时出现连接错误,请注意移动和服务器在同一网络上

这是我的代码:

   File Transfer Example    function getphoto(){ navigator.camera.getPicture(uploadPhoto,function(message) { alert('get picture failed'); },{ quality: 10,destinationType:navigator.camera.DestinationType.FILE_URI,sourceType:navigator.camera.PictureSourceType.PHOTOLIBRARY }); } function uploadPhoto(imageURI) { document.getElementById("myimg").src=imageURI; var options = new FileUploadOptions(); options.chunkedMode = false; options.fileKey="recFile"; var imagefilename = imageURI; options.fileName=imagefilename; options.mimeType="image/jpeg"; // var params = new Object(); //params.value1 = "test"; //params.value2 = "param"; //options.params = params; var ft = new FileTransfer(); alert(imagefilename); //alert(options); //alert(params); ft.upload(imageURI, "http://10.3.150.16/WebSite1/Service.asmx/SaveImage", win, fail, options); } function win(r) { //console.log("Code = " + r.responseCode); //console.log("Response = " + r.response); alert("Sent = " + r.bytesSent); } function fail(error) { switch (error.code) { case FileTransferError.FILE_NOT_FOUND_ERR: alert("Photo file not found"); break; case FileTransferError.INVALID_URL_ERR: alert("Bad Photo URL"); break; case FileTransferError.CONNECTION_ERR: alert("Connection error"); break; } alert("An error has occurred: Code = " + error.code); }         

这是我的asmx我们服务代码:

 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. // [System.Web.Script.Services.ScriptService] public class Service : System.Web.Services.WebService { [WebMethod] public string SaveImage() { HttpPostedFile file = HttpContext.Current.Request.Files["recFile"]; if (file == null) return null; string targetFilePath = "c:\\deposit\\" + file.FileName; file.SaveAs(targetFilePath); return file.FileName.ToString(); } } 

使用代码path.GetFileName(file.FileName) ,即:

 string targetFilePath = "c:\\deposit\\" + Path.GetFileName(file.FileName); 

可能是防火墙问题? 您是否已启用端口80访问外部设备? 请注意,您必须在IIS中托管服务而不是Kasini(默认的visual studio服务)

罗斯