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 ...
随机推荐
- 实战:微信小程序支付开发具体流程
来源:授权地址作者:会编码的熊 该文章纪录了我在开发小程序支付过程中的具体流程 1. 申请微信支付 小程序认证后进入微信支付申请小程序的微信支付 填写企业信息对公账户并上传凭证后,微信支付会打一笔随机 ...
- Mac删除JDK
安装了1.6以后,没有安装1.7发现Android Studio报错: invalid source release: JDK 1.7 原因是Android Studio需要1.7以上的版本,结果再次 ...
- Activity间中使用Intent传值
主页面用来输入一个值传入第二个页面显示,关闭第二个页面返回一个值 主页布局: <RelativeLayout xmlns:android="http://schemas.android ...
- 【数据压缩】LZ77算法原理及实现
1. 引言 LZ77算法是采用字典做数据压缩的算法,由以色列的两位大神Jacob Ziv与Abraham Lempel在1977年发表的论文<A Universal Algorithm for ...
- Node魔法堂:NPM入了个门
一.前言 NPM作为Node的模块管理和发布工具,作用与Ruby的gem.Python的pypl或setuptools.PHP的pear和.Net的Nuget一样.在当前前端工程化极速狂奔的年代,即使 ...
- 上传文件被nginx全部缓存的问题
nginx采用1.5.6. 后端采用nodejs+formidable的方式接受上传文件,本问题的对应与采用什么样的后端没太大关系,这里只是交代一下. 问题: 在前端页面上将文件上传,nginx没有将 ...
- 基于MVC4+EasyUI的Web开发框架经验总结(7)--实现省份、城市、行政区三者联动
为了提高客户体验和进行一些技术探索,现在正准备把我自己的客户关系管理系统CRM在做一个Web的版本,因此对基于MVC的Web界面继续进行一些研究和优化,力求在功能和界面上保持和Winform一致,本文 ...
- C语言写的流氓关机程序及破解
记得大二刚开始接触电脑的那个时候,偶尔会弹出一个强制关机的窗口,当时没有办法,如下: 现在看来只是一个小程序而已,用C语言编写的: #include<windows.h> int main ...
- Allok Video to FLV Converter 可以用的 FixFlash.exe
纸飞机 拷至 c:\windows\system32 ok 下载链接:http://pan.baidu.com/s/1eQwz0DO 软件下载:http://pan.baidu.com/s/1sjGv ...
- jquery层级原则器(匹配后代元素div)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...