Web Service 返回自定义对象

wshcdr 2007-01-17 02:11:39
Web Service 可以返回自定义对象么?
如果可以,请给出示例。
...全文
415 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yan63 2007-01-17
  • 打赏
  • 举报
回复
办法总比问题多

如果图片比较小
把上面的user改一下
public class User
{
public User()
{}
public int id;
public string name;
public string passoword;
public byte[] image;
}
webservice会自动转为base64编码

如果图片比较大
ref:http://www.microsoft.com/china/MSDN/library/archives/library/dnWebsrv/html/wsedime.asp
wshcdr 2007-01-17
  • 打赏
  • 举报
回复
多谢楼上,如果要传递图象数据,怎么做比较合适?
呵呵,我初学Web Service,问题多多
yan63 2007-01-17
  • 打赏
  • 举报
回复
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;

namespace WebSvrTestApp
{
public class User
{
public User()
{}
public int id;
public string name;
public string passoword;
}

/// <summary>
/// Service2 的摘要说明。
/// </summary>
public class Service2 : System.Web.Services.WebService
{
public Service2()
{
//CODEGEN: 该调用是 ASP.NET Web 服务设计器所必需的
InitializeComponent();
}

#region 组件设计器生成的代码

//Web 服务设计器所必需的
private IContainer components = null;

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
}

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

#endregion

// WEB 服务示例
// HelloWorld() 示例服务返回字符串 Hello World
// 若要生成,请取消注释下列行,然后保存并生成项目
// 若要测试此 Web 服务,请按 F5 键

[WebMethod]
public User HelloUser()
{
User user = new User();
user.id = 1;
user.name = "name";
user.passoword = "pwd";

return user;
}
}
}

任何可序列化的类型都可以

12,162

社区成员

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

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