我正在尝试使用Esri请求javascript api上传文件。
esriRequest({
url: "http://localhost:20659/service/Service.svc/Upload/",
form : this.datafile,
handleAs: "json",
callbackParamName: "callback"
},{usePost: true, useProxy:true}).then(lang.hitch(this,function(response){
}), lang.hitch(this,function(error){
console.log(error);
}))
我的wcf服务代码
[OperationContract]
[WebInvoke(Method = "POST",
UriTemplate = "Upload/",
BodyStyle = WebMessageBodyStyle.Bare)]
UploadedFile Upload(System.IO.Stream Uploading);
public UploadedFile Upload(Stream Uploading)
{
UploadedFile upload = new UploadedFile
{
FilePath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString())
};
int length = 0;
using (FileStream writer = new FileStream(upload.FilePath, FileMode.Create))
{
int readCount;
var buffer = new byte[8192];
while ((readCount = Uploading.Read(buffer, 0, buffer.Length)) != 0)
{
writer.Write(buffer, 0, readCount);
length += readCount;
}
}
upload.FileLength = length.ToString();
return upload;
}
我的HTML内容
<form method="post" data-dojo-attach-point="datafile" enctype="multipart/form-data">
<input type="file" name="Upload" id="uploadfile" >
</form>
当我点击上传按钮。我的服务不是打电话,不是任何回复。
但我的WCF服务中的其他方法正在调用。
任何帮助