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 ...
随机推荐
- Mysql在高并发情况下,防止库存超卖而小于0的解决方案
背景: 本人上次做申领campaign的PHP后台时,因为项目上线后某些时段同时申领的人过多,导致一些专柜的存货为负数(<0),还好并发量不是特别大,只存在于小部分专柜而且一般都是-1的状况,没 ...
- C语言学习016:单链表
#include <stdio.h> //定义一个链表,链表是一种递归结构,在定义的时候必须要给结构起一个名字 typedef struct folder{ int level; char ...
- .net又一个生成缩略图的方法,不变形
生成缩略图是一个十分常用功能,找到了一个方法,重写部分代码,实用又好用,.net又一个生成缩略图的方法,不变形 /// <summary> /// 为图片生成缩略图 by 何问起 /// ...
- 【iOS】desctiption和debugDescription
一.简介 与.NET一样,在.NET上得Object对象有个ToString()方法可以用于输出对象的信息,在iOS上的NSObject也有一个方法,为description,该方法返回objc对象的 ...
- 再谈ABC
最近一直在看蒋老师那13篇<我的WCF之旅>,终于看完了,看得很慢,记得最初出来工作的时候那时的技术总监建议我去看的,可几个月前我才开始看,看了几个月才把13篇看完.第一篇WCF的博文是我 ...
- Wojilu学习笔记 (01)
“我记录”开发框架(wojilu framework) 是 .net 平台下的综合开发框架,主要用于 web 方面的快速开发. 官方网址:http://www.wojilu.com源码托管网址: ht ...
- 介绍开源的.net通信框架NetworkComms框架 源码分析(十九 )ConnectionIncomingData
原文网址: http://www.cnblogs.com/csdev Networkcomms 是一款C# 语言编写的TCP/UDP通信框架 作者是英国人 以前是收费的 目前作者已经开源 许可是 ...
- Hello, Android多屏幕版
Hello, Android Multiscreen Xamarin.Android 中处理导航 在这两部指南中,我们将扩展我们前面创建的Phoneword 应用,以处理第二个屏幕.本章主要介绍安卓的 ...
- Hack语言类型化简介
在typechecker的配合下,Hack语言的类型化能力是Hack其他功能特性的基石.开发Hack语言的主要动机也正是为代码提供显式类型标注以便对代码进行类型一致性和潜在错误分析. 这是用于对比Ha ...
- NOSQL学习笔记系列之MongoDB 一 基础
主题:MongoDB 学习资料参考网址: 1.http://www.w3cschool.cc/mongodb/mongodb-tutorial.html 2.http://www.icoolxue.c ...