原创地址: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的更多相关文章

  1. Step by Step 创建一个 Web Service

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

  2. 怎样创建.NET Web Service http://blog.csdn.net/xiaoxiaohai123/article/details/1546941

    为什么需要Web Service 在通过internet网购买商品后,你可能对配送方式感到迷惑不解.经常的情况是因配送问题找配送公司而消耗你的大量时间,对于配送公司而言这也不是一项增值服务. 为了解决 ...

  3. 使用Java创建RESTful Web Service

    REST是REpresentational State Transfer的缩写(一般中文翻译为表述性状态转移).2000年Roy Fielding博士在他的博士论文“Architectural Sty ...

  4. 使用Java创建RESTful Web Service(转)

    REST是REpresentational State Transfer的缩写(一般中文翻译为表述性状态转移).2000年Roy Fielding博士在他的博士论文“Architectural Sty ...

  5. 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 创 ...

  6. 【重点突破】——使用Express创建一个web服务器

    一.引言 在自学node.js的过程中有一个非常重要的框架,那就是Express.它是一个基于NodeJs http模块而编写的高层模块,弥补http模块的繁琐和不方便,能够快速开发http服务器.这 ...

  7. spring3创建RESTFul Web Service

    spring 3支持创建RESTFul Web Service,使用起来非常简单.不外乎一个@ResponseBody的问题. 例如:后台controller: 做一个JSP页面,使用ajax获取数据 ...

  8. C#中自己动手创建一个Web Server(非Socket实现)

    目录 介绍 Web Server在Web架构系统中的作用 Web Server与Web网站程序的交互 HTTPListener与Socket两种方式的差异 附带Demo源码概述 Demo效果截图 总结 ...

  9. eclipes创建一个web项目web.xml不能自动更新的原因(web.xml和@WebServlet的作用)

    在eclipse中创建一个Web项目的时候,虽然有web.xml生成,但是再添加Servlet类文件的时候总是看不见web.xml的更新,所以异常的郁闷!上网查了查,原来我们在创建Web项目的时候,会 ...

随机推荐

  1. sphinx中文入门指南 (转自sphinx中文站)

    Sphinx中文入门指南 wuhuiming<blvming在gmail.com>,转载请注明来源和作者 最后修改:2010年1月23日 1.简介 1.1.Sphinx是什么 1.2.Sp ...

  2. nodejs开发过程中遇到的一些插件记录

    1.chalk Github:https://github.com/chalk/chalk   终端样式定制插件,可自定义输出日志的样式. 1.semver   管网:https://semver.o ...

  3. 《Java并发编程实战》读书笔记一 -- 简介

    <Java并发编程实战>读书笔记一 -- 简介 并发的历史 并发的历史,也是人类利用有限的资源去提高生产效率的一个的例子. 设想现在有台计算机,这台计算机具有以下的资源: 单核CPU一个 ...

  4. yield关键字有什么作用

    所属网站分类: python基础 > 语句 作者:goodbody 链接: http://www.pythonheidong.com/blog/article/10/ 来源:python黑洞网  ...

  5. Ubuntu 15.04 安装配置 Qt + SQLite3

    序 最近需要在Ubuntu下使用Qt开发项目,选择简单小巧的SQLite数据库,现将安装配置以及简单操作记录如下,以便日后查阅. 安装Qt CMake和Qt Creator是Linux下开发C++程序 ...

  6. Cplex: MIP Control Callback

    *本文主要记录和分享学习到的知识,算不上原创 *参考文献见链接 之前,我们有简单提到Cplex中的MIP Callback Interface,包括了Informational callback, q ...

  7. 如何查看Android apk的包名?

    有以下四种方法可以查看apk的包名,之后有别的方法,会接着更新文档的. 1. 安装APK包名查看器; 2. 源码AndroidManifest.xml中查看package包名; 3. 利用" ...

  8. HDU 1561 The more, The Better(树形背包)

    The more, The Better Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  9. CodeForces 570D DFS序 树状数组 Tree Requests

    参考九野巨巨的博客. 查询一个子树内的信息,可以通过DFS序转成线形的,从而用数据结构来维护. #include <iostream> #include <cstdio> #i ...

  10. 关于mysql中select出数据未排序问题

    来自  mysql必知必会