服务应用之WEB与WCF使用之见

摘要:
APP_ CodeWEB:WebService。cs1using系统;2使用System.Collections。通用的3使用系统。Linq;4使用系统。网状物5使用System.Web。服务;67///8///WebService的摘要描述9/////10[WebService(Namespa

APP_Code

WEB:

服务应用之WEB与WCF使用之见第1张服务应用之WEB与WCF使用之见第2张WebService.cs
 1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Web;
5 using System.Web.Services;
6
7 /// <summary>
8 ///WebService 的摘要说明
9 /// </summary>
10 [WebService(Namespace = "http://tempuri.org/")]
11 //[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
12 [WebServiceBinding(ConformsTo = WsiProfiles.None)]
13 //若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
14 // [System.Web.Script.Services.ScriptService]
15 public class WebService : System.Web.Services.WebService {
16
17 public WebService () {
18
19 //如果使用设计的组件,请取消注释以下行
20 //InitializeComponent();
21 }
22
23 [WebMethod(MessageName ="auto")]
24 public string HelloWorld() {
25 return "Hello World";
26 }
27 [WebMethod(MessageName = "HelloWorldByName")]
28 public string HelloWorld(string name) {
29 return "Hello World " + name;
30 }
31
32 }

WCF

服务应用之WEB与WCF使用之见第3张服务应用之WEB与WCF使用之见第4张IService.cs
 1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Runtime.Serialization;
5 using System.ServiceModel;
6 using System.Text;
7
8 // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的接口名“IService”。
9 [ServiceContract]
10 public interface IService
11 {
12 [OperationContract]
13 int Add(int a, int b);
14 [OperationContract]
15 int Subtract(int a, int b);
16 }
服务应用之WEB与WCF使用之见第5张服务应用之WEB与WCF使用之见第6张Service.cs
 1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Runtime.Serialization;
5 using System.ServiceModel;
6 using System.Text;
7
8 // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码、svc 和配置文件中的类名“Service”。
9 public class Service : IService
10 {
11 public int Add(int a, int b)
12 {
13 return a + b;
14 }
15 public int Subtract(int a, int b)
16 {
17 return (a-b);
18 }
19 }

启动文件:

服务应用之WEB与WCF使用之见第7张服务应用之WEB与WCF使用之见第8张Service.svc
1 <%@ ServiceHost Language="C#" Debug="true" Service="Service" CodeBehind="~/App_Code/Service.cs" %>
服务应用之WEB与WCF使用之见第9张服务应用之WEB与WCF使用之见第10张WebService.asmx
1 <%@ WebService Language="C#" CodeBehind="~/App_Code/WebService.cs" Class="WebService" %>

测试:

服务应用之WEB与WCF使用之见第11张服务应用之WEB与WCF使用之见第12张test
 1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Web;
5 using System.Web.UI;
6 using System.Web.UI.WebControls;
7
8 public partial class _Default : System.Web.UI.Page
9 {
10 protected void Page_Load(object sender, EventArgs e)
11 {
12
13 }
14 protected void Button1_Click(object sender, EventArgs e)
15 {
16 AspService.WebService test = new AspService.WebService();
17 Label3.Text = test.HelloWorld();
18 }
19 protected void Button2_Click(object sender, EventArgs e)
20 {
21 AspService.WebService test1 = new AspService.WebService();
22 Label4.Text = test1.HelloWorld(TextBox1 .Text);
23 }
24 protected void Button3_Click(object sender, EventArgs e)
25 {
26 int a = int.Parse(TextBox2.Text);
27 int b = int.Parse(TextBox3 .Text );
28 wcfService.ServiceClient test = new wcfService.ServiceClient();
29 Label5 .Text = test.Add(a, b).ToString ();
30 test.Close();
31 }
32 protected void Button4_Click(object sender, EventArgs e)
33 {
34 int a = int.Parse(TextBox2.Text);
35 int b = int.Parse(TextBox3.Text);
36 wcfService.ServiceClient test1 = new wcfService.ServiceClient();
37 Label5.Text = test1.Subtract(a, b).ToString ();
38 test1.Close();
39 }
40 }








免责声明:文章转载自《服务应用之WEB与WCF使用之见》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇以“图片渐入渐出”为例讲述jQuery插件的具体实现寒假作业总结一下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

WCF入门教程(一)简介

1、WCF是什么? WCF( Windows Communication Foundation), 是Microsoft为构建面向服务的应用提供的分布式通信编程框架,是.NET Framework 3.5的重要组成部分。使用该框架,开发人员可以构建跨平台、安全、可靠和支持事务处理的企业级互联应用解决方案。 简单的说:WCF就是分布式通信框架。  2、WCF...

WPF 窗体程序入口简介

1,直接指定StartupUri为某一个window的子类Window1.xaml(属性指定法) <Application x:Class="brush.App"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.micros...

这几个IDEA高级调试技巧,用完就是香

一个项目启动两次 测试分布式项目时,经常要一个项目启动2次,不用将一个项目打开多次启动,配置一下即可 1.点击Edit Configurations 2.勾选Allow parallel run 3.依次点击如下2个按钮 条件断点 有如下代码,只想让它在i == 10的情况下停下来 @Test public void condition() {...

WCF中的数据契约(Continued)

版本化数据契约 变化是不可避免的。业务的改变,技术的改变,规则的改变,这些都会造成软件契约的变化。面对软件的变化,一个稳定的版本策略是必不可少的。必须注意对不可避免的变化进行预先的筹划,并对当前的客户端保证向后的兼容性。 最常见的对版本化契约的需求是,当现有数据契约中添加新的成员时。按照不间断的版本更改的描述,你可以自由更改,而不需要终止现有的客户端。但...

[转]C# 将类的内容写成JSON格式的字符串

将类的内容写入到JSON格式的字符串中 本例中建立了Person类,赋值后将类中内容写入到字符串中 运行本代码需要添加引用动态库Newtonsoft.Json 程序代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using S...

list采坑记录一下

List<Integer> cards = Lists.newArrayList(6,10,11,12,21,23,29,30,38,39,42,43,46,51,53,59,60);List<Integer> copyList = Lists.newArrayList();copyList = cards;copyList.rem...