Step by Step 创建一个 Web Service
原创地址:http://www.cnblogs.com/jfzhu/p/4022139.html
转载请注明出处
(一)创建Web Service
创建第一个项目,类型选择ASP.NET Empty Web Application


添加一个新项目 Web Service

然后再创建一个类Contact

代码分别如下。
Contact.cs:
[Serializable]
public class Contact
{
private string name; public string Name
{
get { return name; }
set { name = value; }
} private int age; public int Age
{
get { return age; }
set { age = value; }
}
}
HelloWebService.asmx.cs:
/// <summary>
/// Summary description for HelloWebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class HelloWebService : System.Web.Services.WebService
{ [WebMethod]
public string GetMessage(string name)
{
return "Hello " + name;
} [WebMethod]
public Guid CreateContact(Contact c)
{
return Guid.NewGuid();
}
}
(二)创建客户端
下面创建一个客户端调用Web Service,检验一下是否正确。创建一个ASP.NET Empty Web Application

添加服务引用



WebForm1.cs代码为
protected void Button1_Click(object sender, EventArgs e)
{
HelloWebService.HelloWebServiceSoapClient client = new HelloWebService.HelloWebServiceSoapClient();
Label1.Text = client.GetMessage(TextBox1.Text);
} protected void Button2_Click(object sender, EventArgs e)
{
HelloWebService.HelloWebServiceSoapClient client = new HelloWebService.HelloWebServiceSoapClient();
Label2.Text = client.CreateContact(new HelloWebService.Contact()).ToString();
}
最后运行客户端,分别点击按钮,得到演示效果


Step by Step 创建一个 Web Service的更多相关文章
- 转载——Step by Step 创建一个 Web Service
原创地址:http://www.cnblogs.com/jfzhu/p/4022139.html 转载请注明出处 (一)创建Web Service 创建第一个项目,类型选择ASP.NET Empty ...
- 怎样创建.NET Web Service http://blog.csdn.net/xiaoxiaohai123/article/details/1546941
为什么需要Web Service 在通过internet网购买商品后,你可能对配送方式感到迷惑不解.经常的情况是因配送问题找配送公司而消耗你的大量时间,对于配送公司而言这也不是一项增值服务. 为了解决 ...
- 使用Java创建RESTful Web Service
REST是REpresentational State Transfer的缩写(一般中文翻译为表述性状态转移).2000年Roy Fielding博士在他的博士论文“Architectural Sty ...
- 使用Java创建RESTful Web Service(转)
REST是REpresentational State Transfer的缩写(一般中文翻译为表述性状态转移).2000年Roy Fielding博士在他的博士论文“Architectural Sty ...
- 002.Create a web API with ASP.NET Core MVC and Visual Studio for Windows -- 【在windows上用vs与asp.net core mvc 创建一个 web api 程序】
Create a web API with ASP.NET Core MVC and Visual Studio for Windows 在windows上用vs与asp.net core mvc 创 ...
- spring3创建RESTFul Web Service
spring 3支持创建RESTFul Web Service,使用起来非常简单.不外乎一个@ResponseBody的问题. 例如:后台controller: 做一个JSP页面,使用ajax获取数据 ...
- C#中自己动手创建一个Web Server(非Socket实现)
目录 介绍 Web Server在Web架构系统中的作用 Web Server与Web网站程序的交互 HTTPListener与Socket两种方式的差异 附带Demo源码概述 Demo效果截图 总结 ...
- eclipes创建一个web项目web.xml不能自动更新的原因(web.xml和@WebServlet的作用)
在eclipse中创建一个Web项目的时候,虽然有web.xml生成,但是再添加Servlet类文件的时候总是看不见web.xml的更新,所以异常的郁闷!上网查了查,原来我们在创建Web项目的时候,会 ...
- 【重点突破】——使用Express创建一个web服务器
一.引言 在自学node.js的过程中有一个非常重要的框架,那就是Express.它是一个基于NodeJs http模块而编写的高层模块,弥补http模块的繁琐和不方便,能够快速开发http服务器.这 ...
随机推荐
- Beginning Scala study note(6) Scala Collections
Scala's object-oriented collections support mutable and immutable type hierarchies. Also support fun ...
- T-SQL 基本语法
--查询 select DB_ID('B2C') --检查数据库是否存在 if DB_ID('B2C') is not null --使用数据库 use B2C --单引号表示字符串,双引号则不是 U ...
- Mongodb集群搭建的三种方式
转自:http://blog.csdn.net/luonanqin/article/details/8497860 MongoDB是时下流行的NoSql数据库,它的存储方式是文档式存储,并不是Key- ...
- QT操作EXCEL
介绍一下最基本的QT对EXCEL的读写操作. 声明:转载于:http://blog.csdn.net/czyt1988/article/details/52121360 在使用QT的操作数据库的时候, ...
- Fragment滑动切换简单案例
Fragment的产生与介绍Android运行在各种各样的设备中,有小屏幕的手机,超大屏的平板甚至电视.针对屏幕尺寸的差距,很多情况下,都是先针对手机开发一套App,然后拷贝一份,修改布局以适应平板神 ...
- JSTL标签库
JSP页面作为内嵌java的Html简化了Servlet在控制页面显示的语法,但JSP脚本中的表达式功能不够强大,语法也稍显繁杂,EL(Expression Language)表达式语言的出现能够大大 ...
- xpath使用
一.安装(win7 64) 1.安装lxml,pip install lxml 2.如果安装出错,下载lxml-3.5.0b1.win-amd64-py2.7.exe: 地址:http://www.l ...
- Linux下搭建coreseek(sphinx+mmseg3)全文检索
测试平台:Center OS 1.设置环境,升级/安装系统基础依赖包:m4.autoconf.automake.libtool #设置路径和中文环境: $ export PATH=/usr/local ...
- iOS 遇到的错误总结
1.[[[NSBundle mainBundle] loadNibNamed:@"UIFeedbackController" owner:nil options:nil] firs ...
- java的基础知识文件操作和标识符
1.文件夹的操作 dir :显示当前文件夹中的所有文件和文件夹. cd 路径: 进入到指定的路径. cd .. : 回到上一级目录 cd \ : 回到当前目录的跟目录 md 文件夹名 创建一个 ...