Web Service的基本实例
来源:互联网 发布:韩公主原型事件知乎 编辑:程序博客网 时间:2024/06/15 05:02
Web Service的基本实例
首先知道创建WebService的基本步骤是什么?
(1) 首先在Asp.net中创建一个Asp.Net Web 服务。
(2) 在WebService.cs中创建一个方法。如:
[WebMethod] //方法必须加上这个;
Public int add(int a,int b)
{
Int sum;
Sum=a+b;
Return sum;
}
(3) 然后通过visual studio 2005/2008命令提示符“ WSDL http://localhost:1755/Addnumbers/WebService.asmx?op=add /out:自己起一个类名.cs //http://localhost:1755/Addnumbers/WebService.asmx?op=add 为文件的url;” 生成一个类名;
(4) 接下来执行的是:csc /t:library (3)执行的类名,然后生成(3)的类名.dll文件。
(5)在别的机器上如何引用:在vs 2005项目上添加WEB引用把他的路径写到URL上。Web参考名称可以自己写。然后点击确定。
(6)在cs文件中 。用WEB参考名.WebService 然后实例化;
然后是 实例化名称.方法名;
实例:vs 2005 webservice.asmx
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
/// <summary>
/// WebService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService {
public WebService () {
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod]
public string HelloWorld() {
return "Hello World";
}
[WebMethod]
public int add(int a,int b)
{
int sum;
sum = a + b;
return sum;
}
}
Vs 2008调用:
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
int x = 5;
int y = 10;
int sum;
FN.WebService fs = new FN.WebService();
Response.Write( fs.add(x, y).ToString());
}
}
- Web Service的基本实例
- Web Service的基本定义
- 简单的web service实例
- Web (WCF) Service设计的 基本观念
- Axis开发Web Service的实例
- 一个实用的java web service 实例
- JAX-WS的Web Service实例
- Web Service基本介绍
- Web service开发实例
- .net web service实例
- Web Service 实例
- java web service实例
- web Service入门实例
- web Service入门实例
- Web Service实例
- Web Service实例测试
- Java web service 实例
- web service实例
- js实现图片滚动
- 《定风波》 苏轼
- MSSQL数据库质疑的解决方案 (转贴)
- 排序算法大汇总c语言
- 数据转换与性能
- Web Service的基本实例
- 曾国藩格言十二首
- 更改了启动驱动器的 SATA 模式后启动基于 Windows Vista 的计算机时收到错误消息:“STOP 0x0000007B INACCESSABLE_BOOT_DEVICE”
- $(document).ready(function(){ $("#usercenter .menu").mouseover(function(){ $(this).addClass("over");}).mouseout(function(){ $
- 算法集锦,将不断添加
- Web负载均衡解决方案 HAproxy
- Struts2开发常见问题
- Ex7_5写一个函数,用"冒泡排序"对输入的10个整数从小到大排序
- 隐性语义索引