利用SOAP(Webservice)上传文件
2024-07-21 02:21:18
供稿:网友
本文系鼎鼎原创,如转载,请注明出处:http://blog.csdn.net/weisunding
[webmethod(description="上传并保存图片文件")]
public bool savefile(byte[] bindata,string filename){
bool success=false;
string savepath=system.configuration.configurationsettings.appsettings["uploaddirectory"];
if(savepath==null) savepath="photo";
if(savepath.indexof("://")<0) savepath=server.mappath(savepath);//不是绝对路径
if(!savepath.endswith("//")) savepath += "//";
if(!directory.exists(savepath)){
throw new exception("服务器端没有找到有效的保存路径!");
}
filestream filestream=null;
try{
filestream=new filestream(savepath + filename,filemode.create,fileaccess.write);
//write the file
filestream.write(bindata,0,bindata.length);
filestream.flush();//clear the buffer,write the data to the hard disk
success=true;
}catch(exception ex){
throw new exception(ex.message);
}finally{
filestream.close();
}
return success;
}
解决思路:编写webservice过程savefile(byte[] bindata,string filename0;
客户端直接用调用,把数据流作参数传上来就完了。