WebService应用:音乐站图片上传

简介:

我们的音乐站以前由于图片放在196上导致连接数过多,用户无法听歌,后来所有音乐站专辑的图片就转到了数据库中.那知道现在就变成了数据库连接数过多或者是连接池不够了,导致网站经常报错,那好吧,图片又转移.这会就直接转移到Web服务器上了,直接作为一般的网站图片存放.

龚军勇已经写了个程序把所有数据库的图片转移到Web服务器上了,但是现在要更新新专辑怎么办?于是龚提出的一个办法就是专门写了一个页面,执行这个页面,把专辑ID传过去,那么就可以把数据库中的图片复制到Web服务器.个人觉得这个方法还是比较麻烦,但是要在Web服务器上开FTP吧似乎也不好,于是我想到了一个办法,那就是在音乐站中写一个WebService,然后在专辑上传程序中调用这个WebService就可以把图片写到Web服务器上,而不需要在服务器上再开启其他的什么服务.

具体做法如下:

服务端:

[WebMethod]
public string WritePic(byte[] src, int id)//src为图片字节数组,id为专辑的id
{
try
{
MemoryStream msImage = new MemoryStream(src);
Image imgFile = Image.FromStream(msImage);
string path = Server.MapPath(".");
imgFile.Save(path + "\\" + id + ".jpg", ImageFormat.Jpeg);
imgFile.Dispose();
}
catch (Exception ex)
{
return ex.Message;
}
return "Success";
}

客户端调用:

FileStream fs = new FileStream(fileName, FileMode.Open);
BinaryReader br = new BinaryReader(fs);
byte[] pic=br.ReadBytes((int)fs.Length);
UsingWebService.localhost.Service s = new UsingWebService.localhost.Service();//调用Web服务
MessageBox.Show(s.WritePic(pic,Convert.ToInt32(textBox1.Text)));//显示操作结果
br.Close();
fs.Close();

目录
相关文章
|
4月前
|
XML Java 应用服务中间件
WebService - Axis2基于JAX-WS开发WebService并发布多个WebService
WebService - Axis2基于JAX-WS开发WebService并发布多个WebService
36 0
|
4月前
|
Java 应用服务中间件 Spring
WebService - Axis2使用services.xml进行开发server与client(未与Spring整合)
WebService - Axis2使用services.xml进行开发server与client(未与Spring整合)
44 0
|
4月前
|
Java 应用服务中间件 Spring
WebService - CXF开发Server和Client(main方法测试)
WebService - CXF开发Server和Client(main方法测试)
40 0
|
Java Android开发
哇!eclipse+webservice开发实例居然这样写(有源码可用)
哇!eclipse+webservice开发实例居然这样写(有源码可用)
107 0
哇!eclipse+webservice开发实例居然这样写(有源码可用)
|
Java 应用服务中间件 Apache
webservice开发不得不知的细节,Error creating bean with name ‘org.apache.cxf.jaxws.EndpointImpl---1987203924‘
webservice开发不得不知的细节,Error creating bean with name ‘org.apache.cxf.jaxws.EndpointImpl---1987203924‘
125 0
|
缓存 应用服务中间件 数据库
python web service开发
记录第一个web python服务
9819 0
python web service开发
|
C++ 网络架构
根据wsdl使用gsoap开发webservice服务和客户端总结
基于wsdl使用gsoap开发webservice服务和客户端
1953 0
|
Web App开发 Java Apache
|
测试技术 Java 应用服务中间件