我爱Aspx >> Asp.Net >> WebService上传下载文件实例/// ConvertStreamToByteBuffer:把给定的文件流转换为二进制字节数组。
/// </summary>
/// <param name="theStream"></param>
/// <returns></returns>
public byte[] ConvertStreamToByteBuffer(System.IO.Stream theStream)
{
int b1;
System.IO.MemoryStream tempStream = new System.IO.MemoryStream();
while((b1=theStream.ReadByte())!=-1)
{
tempStream.WriteByte(((byte)b1));
}
return tempStream.ToArray();
}
[WebMethod(Description="Web 服务提供的方法,返回给定文件类型。")]
public string GetImageType()
{
///这里只是测试,您可以根据实际的文件类型进行动态输出
return "image/jpg";
}
}
}
}
一旦我们创建了上面的asmx文件,进行编译后,我们就可以编写客户端的代码来进行调用这个Web Services了。
我们先“添加Web引用”,输入:http://localhost/aspxWebCS/GetBinaryFile.asmx。下面,我们编写显示文件的中间文件:GetBinaryFileShow.aspx,这里,我们只需要在后代码里编写代码即可,GetBinaryFileShow.aspx.cs文件内容如下:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Services;
namespace aspxWebCS
{
/// <summary>
/// GetBinaryFileShow 的摘要说明。
/// </summary>
public class GetBinaryFileShow : System.Web.UI.Page
Ҷƪл˵?
在vs2005 web程序里如何做固定表..[04-21]
编写高性能Web 应用程序的 10 个..[04-21]
整理Web开发-Ajax社区中有关Ajax..[04-21]
韩国的WEB2.0网站列表[04-21]
分析:面向Web的数据挖掘面临3大..[03-18]
VS2005+Crystal Report开发Web应..[03-17]
ASP.NET+Atlas创建客户端Web应用..[03-17]
ASP.NET+Atlas创建客户端Web应用..[03-17]
VS2005+Crystal Report开发Web应..[03-17]
三层Web体系结构里的两种数据绑定..[03-16]
Data Access Application Block ..[04-21]
Exception Handing Applcation B..[04-21]
了解c#2.0中的Anonymous Methods[04-21]
C#2.0泛型学习--入门篇[04-21]
FileSystemWatcher--检测系统文件..[04-21]
怎样隐藏快捷菜单(C#)[04-21]
ASP.NET2.0中配置文件的加密与解..[04-21]
asp.net2.0新增加的安全控件(译)[04-21]
c#操作xml类[04-21]
本站photos模块代码[04-21]