webservice简单引用
//1.创建网站
//2.新建项=>添加web服务
//运行texttweb.asmx可以通过访问http://域名/webservice/texttweb.asmx来验证了
//3.添加服务引用=>发现服务=>确定添加
//4.添加窗体调用webservive对外发布的方法,可以调用显示webservice对外开发的方法了
web服务
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Services; /// <summary>
/// textweb 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。
// [System.Web.Script.Services.ScriptService]
public class textweb : System.Web.Services.WebService { public textweb () { //如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod(Description="这个方法返回一个查询数据库数据结果")]
public string HelloWorld()
{
string name = "";
string conString = "data source=.;initial catalog=Texts;user id=sa;pwd=023812;";
using (SqlConnection con = new SqlConnection(conString))
{
con.Open();
string sql = "select name from Student where id = 5";
SqlCommand com = new SqlCommand(sql, con);
name = com.ExecuteScalar().ToString();
}
return name;
}
[WebMethod(Description = "这个方法计算加法")]
public int Sum(int a,int b) //提供对外的调用
{
return a + b;
} }
web窗体
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Label ID="Label1" runat="server" Text="+"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="=" />
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> </div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
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)
{
textweb web = new textweb();//实例化webservice对象
//调用webservice对象提供的方法
TextBox3.Text = web.Sum(Convert.ToInt32(TextBox1.Text), Convert.ToInt32(TextBox2.Text)).ToString();
}
}
webservice简单引用的更多相关文章
- 主题:Java WebService 简单实例
链接地址:主题:Java WebService 简单实例 http://www.iteye.com/topic/1135747 前言:朋友们开始以下教程前,请先看第五大点的注意事项,以避免不必要 ...
- WebService简单教程
一.简介 1.什么是WebService? WebService是一个SOA(面向服务的编程)的架构,它是不依赖于语言,不依赖于平台,可以实现不同的语言间的相互调用,通过Internet进行基于Htt ...
- WebService 简单安全验证
原文:WebService 简单安全验证 最近新接了一个需要调用第三方WebService的项目,看到这个第三方WebService被调用的时候,需要授权用户名和密码,于是自己也想对WebServic ...
- 使用 CXF 做 webservice 简单例子(转载)
使用 CXF 做 webservice 简单例子 Apache CXF 是一个开放源代码框架,提供了用于方便地构建和开发 Web 服务的可靠基础架构.它允许创建高性能和可扩展的服务,您可以将这 ...
- .net实现webservice简单实例分享
原理:WebService是一个SOA(面向服务的编程)的架构,它是不依赖于语言,不依赖于平台,可以实现不同的语言间的相互调用,通过Internet进行基于Http协议的网络应用间的交互.作用:主要用 ...
- .net请求Webservice简单实现天气预报功能
很久没有接触Webservice的知识,今天稍微复习了一下关于webservice,简单做了一个天气预报的功能,虽然界面丑的厉害,但功能算是实现了,以下是效果展示. 这东西没什么难点,只是天气预报的功 ...
- VS2008中C#开发webservice简单实例
1.创建工程 文件-> 新建->网站 如下图. 工程建好后,会自动添加如下代码: using System; using System.Linq; using System.Web; us ...
- C# 创建、部署和调用WebService简单示例
webservice 可以用于分布式应用程序之间的交互,和不同程序之间的交互. 概念性的东西就不说太多,下面开始创建一个简单的webservice的例子.这里我用的是Visual Studio 201 ...
- Webservice简单案例
东西不用,时间长了就会被忘掉.重新拾起来 做一个简单的Demo,便于以后的查询 服务器端--新建Calculator.asmx using System; using System.Collectio ...
随机推荐
- iOS-地图报错超出了经纬度范围Invalid Region
做地图定位的时候,使用一下代码 // 经纬度 CLLocationDegrees latitude = [storeDict[@"lat"] doubleValue]; CLLoc ...
- 简单的jquery拖曵原理js特效实例
<!DOCTYPE html> <html> <title>简单拖曵原理实例</title> <script language="jav ...
- JAVA 设计模式 外观模式
用途 外观模式 (Facade) 为子系统中的一组接口提供一个一致的界面,此模式定义了一个高层接口,这个接口使得这一子系统更加容易使用. 外观模式是一种结构型模式. 结构
- 第20/24周 死锁(Deadlocking)
大家好,欢迎回到性能调优培训.今天讨论SQL Server里的死锁(Deadlocking),第5个月的培训就结束了.当2个查询彼此等待,没有查询可以继续它的工作就会发生死锁.第一步我会概括介绍下SQ ...
- IOS 回收键盘通用代码
感觉IOS的键盘回收好累,所以封装了一个通用一点的方法 -(IBAction)spbResignFirstResponder:(id)sender { // NSLogObj(sender); if ...
- 解决64位Windows2003程序字体很小的问题
先看问题现象: 如图,字小的一B,并且无法通过更改主题字体大小.对话框字体等操作得到解决. 注:该问题可能不限于64位Windows2003,看完解决方法你就明白了,是有个注册表键值缺失或设置不当造成 ...
- EF CodeFirs 代码迁移、数据迁移
最近悟出来一个道理,在这儿分享给大家:学历代表你的过去,能力代表你的现在,学习代表你的将来. 十年河东十年河西,莫欺少年穷 学无止境,精益求精 标题叫EF CodeFirs 代码迁移.数据迁移. ...
- MFC 阶段学习总结
由于项目需求,需要用到C++开发软件,所以开始学习C++,重点是MFC,因为是窗体应用,感觉win32的比较麻烦,还是MFC方便点.至于为什么要用C++呢, 由于C++应用不需要客户额外安装环境和加密 ...
- EntityFramework中几种更改数据的方式
首先声明个实体类,该实体类是EntityFrameWork自动生成的,对应数据表Test结构如下 public partial class Test { public int Id{ get; set ...
- Xcode push带有cocoapods类库的项目到git仓库
关于git之一点不熟悉,以前公司的项目搭建,版本控制这块,都是有专门的人在做,当然那时候也是用的git项目中也包含了cocoapods类库,当前公司比较闲, 所以研究了下git,用的是git.osch ...