![C#WebService入门.docx_第1页](http://file.renrendoc.com/FileRoot1/2020-1/12/4f27a8ed-defd-489a-97ec-e5b5565a0370/4f27a8ed-defd-489a-97ec-e5b5565a03701.gif)
![C#WebService入门.docx_第2页](http://file.renrendoc.com/FileRoot1/2020-1/12/4f27a8ed-defd-489a-97ec-e5b5565a0370/4f27a8ed-defd-489a-97ec-e5b5565a03702.gif)
![C#WebService入门.docx_第3页](http://file.renrendoc.com/FileRoot1/2020-1/12/4f27a8ed-defd-489a-97ec-e5b5565a0370/4f27a8ed-defd-489a-97ec-e5b5565a03703.gif)
![C#WebService入门.docx_第4页](http://file.renrendoc.com/FileRoot1/2020-1/12/4f27a8ed-defd-489a-97ec-e5b5565a0370/4f27a8ed-defd-489a-97ec-e5b5565a03704.gif)
![C#WebService入门.docx_第5页](http://file.renrendoc.com/FileRoot1/2020-1/12/4f27a8ed-defd-489a-97ec-e5b5565a0370/4f27a8ed-defd-489a-97ec-e5b5565a03705.gif)
已阅读5页,还剩5页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
2014年7月28日星期一By JorgenXu一:基本概念(1) WebService完全基于XML,它只是一个协议,相当于http协议。(2) WebService基于Http通信(3) SOAP消息格式/WSDL描述/UDDI目录浏览本人理解:相当于传递一个XML文件到后台程序,程序去解析XML,进一步执行XML里指定要执行的事件。不过XML要遵守一定的写法,否则后台解析的时候不认识。二:VS2010创建1:创建流程(1) 打开VS2010,新建项目(2) Framework4.0 如上图没有提供WebService模板,点击选择.net2.0,选择web服务应用程序using System;using System.Collections.Generic;using System.Web;using System.Web.Services;namespace WebService1 / / Service1 的?摘a要a说明 / WebService(Namespace = /) WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1) System.ComponentModel.ToolboxItem(false) public class Service1 : System.Web.Services.WebService WebMethod public string HelloWorld() Thread.Sleep(3000);/调用?测a试?使1用? return Hello World; (3) 默认后台 (4) 运行效果2:添加方法(1) 添加如下代码 public class Service1 : System.Web.Services.WebService WebMethod public string HelloWorld() Thread.Sleep(3000);/调用测试使用 return Hello World; WebMethod(Description=方?法注释) public string MyTest(string text) return this is my Test WebService + text; (2) 运行效果三:使用调用1:Web使用WebService1.1 同步调用(1) 新建个web项目,选择添加web引用(2) 输入上webService地址,添加引用(3) 在Default页面后台输入如下代码 public partial class _Default : System.Web.UI.Page protected void Page_Load(object sender, EventArgs e) void MySever_HelloWorldCompleted(object sender, localhost.HelloWorldCompletedEventArgs e) Response.Write(e.Result); protected void 调用_Click(object sender, EventArgs e) localhost.Service1 MySever = new localhost.Service1(); /MySever.HelloWorldCompleted += new localhost.HelloWorldCompletedEventHandler(MySever_HelloWorldCompleted); /MySever.HelloWorldAsync(); Response.Write( MySever.HelloWorld(); Response.Write(我后执行); (4) 运行查看效果1.2 异步调用(1) 设置页面可以异步(2) 添加按钮事件,后台代码如下 public partial class _Default : System.Web.UI.Page protected void Page_Load(object sender, EventArgs e) void MySever_HelloWorldCompleted(object sender, localhost.HelloWorldCompletedEventArgs e) Response.Write(e.Result); protected void 调用_Click(object sender, EventArgs e) localhost.Service1 MySever = new localhost.Service1(); MySever.HelloWorldCompleted += new localhost.HelloWorldCompletedEventHandler(MySever_HelloWorldCompleted); MySever.HelloWorldAsync(); / Response.Write( MySever.HelloWorld(); Response.Write(我先执行); (3) 运行效果。可以看到“我先执行”在”Hello World”前1.3 JS Ajax调用 function DoWebService() $.ajax( type: POST, url: http:/localhost:11145/Service1.asmx/MyTest, data:text:这是测试, success: function (msg) alert(msg.text); ); (1) 部分代码(2) 运行效果2: Winform 使用WebService引用方法和Web相同,效果图三:优缺点 款平台。各种设备包括手机、PC等。 利于开发维护。例: bs/cs程序 都可以调用WebService接口方法。开发的时,不用两遍都写,建一个WebSe
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年三片式球阀项目发展计划
- 2025年度汽车销售市场调研与分析合同
- 2025版商业综合体电梯清洁维护协议
- 2022年江苏高考英语真题及答案-2
- 2025年度健康食堂牛羊肉绿色采购配送协议4篇
- 2025年度足疗行业市场调研分析合同
- 2025年全自动滗水器合作协议书
- 幼儿园节奏感与韵律教育方案计划
- 班级活动与团队合作训练计划
- 跨学科合作项目的设计与实践计划
- JBT 1472-2023 泵用机械密封 (正式版)
- 价格法价格违法行为和明码标价法律法规价格欺诈知识
- 2016-2023年山东力明科技职业学院高职单招(英语/数学/语文)笔试历年参考题库含答案解析
- 中外历史纲要上大事年表
- 高标准农田建设项目监理计划
- 2022版《义务教育教学新课程标准》解读课件
- 小学二年级(上册)-乘法口诀-练习题-A4直接打印
- 采购行业的swot分析
- 设备采购 投标方案(技术方案)
- 振荡指标MACD(波段操作精解)
- 儿科常见病的病例讨论和诊断思维培训课件
评论
0/150
提交评论