遇到麻烦了!请各位帮忙!

yuranccc2003 2005-04-19 12:30:02
孟子e章里面的用webservice文章,
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.UI;
using System.Web.Services;
using System.IO;

namespace xml.sz.luohuedu.net.aspxWebCS
{
/// <summary>
/// GetBinaryFile 的摘要说明。
/// Web Services名称:GetBinaryFile
/// 功能:返回服务器上的一个文件对象的二进制字节数组。
/// </summary>
[WebService(Namespace="http://xml.sz.luohuedu.net/",
Description="在Web Services里利用.NET框架进行传递二进制文件。")]
public class GetBinaryFile : System.Web.Services.WebService
{

#region Component Designer generated code
//Web 服务设计器所必需的
private IContainer components = null;

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}

#endregion

public class Images: System.Web.Services.WebService
{
/// <summary>
/// Web 服务提供的方法,返回给定文件的字节数组。
/// </summary>
[WebMethod(Description="Web 服务提供的方法,返回给定文件的字节数组")]
public byte[] GetImage(string requestFileName)
{
///得到服务器端的一个图片
///如果你自己测试,注意修改下面的实际物理路径
if(requestFileName == null || requestFileName == "")
return getBinaryFile("D:\\Picture.JPG");
else
return getBinaryFile("D:\\" + requestFileName);
}

/// <summary>
/// getBinaryFile:返回所给文件路径的字节数组。
/// </summary>
/// <param name="filename"></param>
/// <returns></returns>
public byte[] getBinaryFile(string filename)
{
if(File.Exists(filename))
{
try
{
///打开现有文件以进行读取。
FileStream s = File.OpenRead(filename);
return ConvertStreamToByteBuffer(s);
}
catch(Exception e)
{
return new byte[0];
}
}
else
{
return new byte[0];
}
}
/// <summary>
/// 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.cs代码在aspx页面添加web引用,引用名怎么写?
添加了web引用后,还要用using 加吗?

xml.sz.luohuedu.net.aspxWebCS.GetBinaryFile.Images oImage;
oImage = new xml.sz.luohuedu.net.aspxWebCS.GetBinaryFile.Images();
byte[] image = oImage.GetImage("");
这段代码为什总是找不到引用呢?

[WebService(Namespace="http://xml.sz.luohuedu.net/",Description="在Web Services里利用.NET框架进行传递二进制文件。")]
这段代码具体是什么用的呢?
用wsdl 查看,好象什么也没有啊!!
...全文
159 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuranccc2003 2005-04-21
  • 打赏
  • 举报
回复
可以引用,但是
xml.sz.luohuedu.net.aspxWebCS

提示找不到引用名,要从新添加,
晕死了。
andy_lsh 2005-04-21
  • 打赏
  • 举报
回复
不明白,你的意思是你没办法再项目中添加web service的引用吗?
yuranccc2003 2005-04-21
  • 打赏
  • 举报
回复
up
lyb_abiandbel 2005-04-20
  • 打赏
  • 举报
回复
怎么没有人啊?

12,162

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 Web Services
社区管理员
  • Web Services社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧