博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
webservice简单引用
阅读量:7037 次
发布时间:2019-06-28

本文共 2501 字,大约阅读时间需要 8 分钟。

//1.创建网站

//2.新建项=>添加web服务
//运行texttweb.asmx可以通过访问http://域名/webservice/texttweb.asmx来验证了
//3.添加服务引用=>发现服务=>确定添加
//4.添加窗体调用webservive对外发布的方法,可以调用显示webservice对外开发的方法了

web服务

1 using System; 2 using System.Collections.Generic; 3 using System.Data.SqlClient; 4 using System.Linq; 5 using System.Web; 6 using System.Web.Services; 7  8 ///  9 /// textweb 的摘要说明10 /// 11 [WebService(Namespace = "http://tempuri.org/")]12 [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]13 // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 14 // [System.Web.Script.Services.ScriptService]15 public class textweb : System.Web.Services.WebService {16 17     public textweb () {18 19         //如果使用设计的组件,请取消注释以下行 20         //InitializeComponent(); 21     }22     [WebMethod(Description="这个方法返回一个查询数据库数据结果")]23     public string HelloWorld()24     {25         string name = "";26         string conString = "data source=.;initial catalog=Texts;user id=sa;pwd=023812;";27         using (SqlConnection con = new SqlConnection(conString))28         {29             con.Open();30             string sql = "select name from Student where id = 5";31             SqlCommand com = new SqlCommand(sql, con);32             name = com.ExecuteScalar().ToString();33         }34         return name;35     }36     [WebMethod(Description = "这个方法计算加法")]37     public int Sum(int a,int b) //提供对外的调用38     {39         return a + b;40     }41     42 }
View Code

web窗体

1 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 2  3  4  5  6  7 
8 9 10 11
12
13 14
15
16
17
18
19 20
21
22 23
View Code
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Web; 5 using System.Web.Security; 6 using System.Web.UI; 7 using System.Web.UI.WebControls; 8 using System.Web.UI.WebControls.WebParts; 9 using System.Xml.Linq;10 11 public partial class _Default : System.Web.UI.Page12 {13     protected void Page_Load(object sender, EventArgs e)14     {15 16     }17     protected void Button1_Click(object sender, EventArgs e)18     {19         textweb web = new textweb();//实例化webservice对象20         //调用webservice对象提供的方法21         TextBox3.Text = web.Sum(Convert.ToInt32(TextBox1.Text),       Convert.ToInt32(TextBox2.Text)).ToString();22     }23 }
View Code

 

转载于:https://www.cnblogs.com/LiuZhen/p/3723926.html

你可能感兴趣的文章
resin app server安装总结
查看>>
订单信息表和订单明细表
查看>>
背包九讲
查看>>
AS莫名报错 Error:Could not download junit.jar (junit:junit:4.12): No cached version available
查看>>
右侧客服 运动案例
查看>>
T4 Editor地址
查看>>
小程序文档
查看>>
QQ分享-定制分享卡片
查看>>
DataTable的用法
查看>>
17_服务器提权
查看>>
Python文件指针与Python函数
查看>>
免费16WiFi被吐槽
查看>>
移动UI自动化-Page Objects Pattern
查看>>
-------分割线------\n FriskyPuppy的图论学习之路!
查看>>
JZ2440 裸机驱动 第13章 LCD控制器(2)
查看>>
连邦IT服务IT用户、厂商和服务商
查看>>
浪潮信息10亿投向云计算
查看>>
SVN分支与主干
查看>>
读书笔记--精通CSS高级Web标准解决方案(二)---CSS基础之CSS选择器
查看>>
NodeJS基础(一)
查看>>