Web service
来源:互联网 发布:java 时间戳处理 编辑:程序博客网 时间:2024/06/05 09:02
最近在有接触web Service,了解到Web Service 中的方法不能重载,不能有输出参数。想返回多个值的话,方法返回对象。
对象model代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data ;
namespace MyWebService
{
public class ReturnObject
{
private string _Msg;
public string Msg
{
get { return _Msg; }
set { _Msg = value; }
}
private DataTable _dtRecord;
public DataTable dtRecord
{
get { return _dtRecord; }
set { _dtRecord = value; }
}
private bool _isSuccess;
public bool isSuccess
{
get { return _isSuccess; }
set { _isSuccess = value; }
}
private int _rowCount;
public int rowCount
{
get { return _rowCount; }
set { _rowCount = value; }
}
}
}
service方法:
[WebMethod(Description="返回对象")]
public ReturnObject getUserIfo()
{
DataSet ds = new DataSet();
ReturnObject rbReturn = new ReturnObject();
try
{
string strsql = "Select USERID,USERNAME,TELEPHONE from USERS";
ds = SqlHelper.GetDataSet(strsql);
rbReturn.dtRecord = ds.Tables[0];
rbReturn.rowCount = ds.Tables[0].Rows.Count;
rbReturn.isSuccess = true;
}
catch (Exception ex)
{
rbReturn.Msg = ex.ToString();
rbReturn.isSuccess = false;
throw ex;
}
return rbReturn;
}
[WebMethod(Description="返回的对象序列化")]
public string getUserIfoSerialize()
{
DataSet ds = new DataSet();
ReturnObject rbReturn = new ReturnObject();
try
{
string strsql = "Select * from MyInfo";
ds = SqlHelper.GetDataSet(strsql);
rbReturn.dtRecord = ds.Tables[0];
rbReturn.rowCount = ds.Tables[0].Rows.Count;
rbReturn.isSuccess = true;
}
catch (Exception ex)
{
rbReturn.Msg = ex.ToString();
rbReturn.isSuccess = false;
throw ex;
}
string strResult = JsonConvert.SerializeObject(rbReturn, Formatting.Indented);
return strResult;
}
后台调用webService :前台button
protected void Button1_Click(object sender, EventArgs e)
{
LocalService.Service1SoapClient web = new LocalService.Service1SoapClient();
string str = web.getUserIfoSerialize();
}
- Web Service
- Web Service
- web-service
- Web Service
- web service
- Web Service
- WEB SERVICE
- WEB SERVICE
- web service
- Web Service
- Web Service
- web service
- web service
- Web Service
- Web Service
- Web Service
- Web Service
- Web Service
- 如何快速的在pdf文件中添加水印
- c++primer第一章入门
- 网络工程____网线水晶头的制作
- Android 编译FFmpeg x264
- 再次改进市售的蓝牙鼠标
- Web service
- [Power] 如果抓取功耗问题 log
- C#之while与do……while语句
- 【工作笔记】从零开始学ElasticSearch( 八)—— 数据(CRUD语法)
- DWR消息推送演示
- 为什么需要内存对齐?
- MATLAB中模糊神经网络工具箱的使用
- APPIUM学习2
- [编程题]iNOC产品部-杨辉三角的变形