Web Service(0):用Web Service实现两个整数运算

最近,项目开发中需要用到Web Service.自己在网上搜集资料.自己做了一个小例子,用来加深自己对Web Service理解.

概念:Web Service主要是为了使原来各孤立的站点之间的信息能够相互通信、共享而提出的一种接口。 Web Service所使用的是Internet上统一、开放的标准,如HTTP、XML、SOAP(简单对象访问协议)、WSDL等,所以Web Service可以在任何支持这些标准的环境(Windows,Linux)中使用。注:SOAP协议(Simple Object Access Protocal,简单对象访问协议),它是一个用于分散和分布式环境下网络信息交换的基于XML的通讯协议。在此协议下,软件组件或应用程序能够通过标准的HTTP协议进行通讯。它的设计目标就是简单性和扩展性,这有助于大量异构程序和平台之间的互操作性,从而使存在的应用程序能够被广泛的用户访问.

这是Web Service服务端MyWeb Service.asmx文件代码:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Web;
 4 using System.Web.Services;
 5
 6 /// <summary>
 7 ///MyWebService 的摘要说明
 8 /// </summary>
 9 [WebService(Namespace = "http://tempuri.org/")]
10 [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
11 public class MyWebService : System.Web.Services.WebService {
12
13     public MyWebService () {
14
15         //如果使用设计的组件,请取消注释以下行
16         //InitializeComponent();
17     }
18     [WebMethod(Description = "求和的方法")]
19     public double addition(double i,double j)
20     {
21         return i + j;
22     }
23     [WebMethod(Description = "求差的方法")]
24     public double subtract(double i,double j)
25     {
26         return i - j;
27     }
28     [WebMethod(Description = "求积的方法")]
29     public double multiplication(double i, double j)
30     {
31         return i * j;
32     }
33     [WebMethod(Description = "求商的方法")]
34     public double division(double i, double j)
35     {
36         if (j != 0)
37         {
38             return i / j;
39         }
40         else
41         {
42             return 0;
43         }
44     }
45 }

这是客户端前台index.aspx文件代码:

 1 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="index.aspx.cs" Inherits="index" %>
 2
 3 <!DOCTYPE html>
 4
 5 <html xmlns="http://www.w3.org/1999/xhtml">
 6 <head runat="server">
 7     <title></title>
 8 </head>
 9 <body>
10     <form id="form1" runat="server">
11     <div>
12         <asp:TextBox ID="Num1" runat="server"></asp:TextBox>
13         <select id="selectOper" runat="server">
14             <option>+</option>
15             <option>-</option>
16             <option>*</option>
17             <option>/</option>
18         </select>
19         <asp:TextBox ID="Num2" runat="server"></asp:TextBox>
20         <asp:Button ID="Button1" runat="server" Text="=" onclick="Button1_Click"/>
21         <asp:TextBox ID="Result" runat="server"></asp:TextBox>
22         </div>
23     </form>
24 </body>
25 </html>

这是客户端index.aspx.cs文件代码:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Web;
 4 using System.Web.UI;
 5 using System.Web.UI.WebControls;
 6
 7 public partial class index : System.Web.UI.Page
 8 {
 9     protected void Page_Load(object sender, EventArgs e)
10     {
11
12     }
13     protected void Button1_Click(object sender, EventArgs e)
14     {
15         string selectFlag = selectOper.Value;
16         MyWebService.MyWebService web = new MyWebService.MyWebService();
17         if(selectFlag.Equals("+"))
18         {
19         Result.Text=(web.addition(double.Parse(Num1.Text),double.Parse(Num2.Text))).ToString();
20         }
21         else if (selectFlag.Equals("-"))
22         {
23          Result.Text = (web.subtract(double.Parse(Num1.Text), double.Parse(Num2.Text))).ToString();
24         }
25         else if (selectFlag.Equals("*"))
26         {
27             Result.Text = (web.multiplication(double.Parse(Num1.Text), double.Parse(Num2.Text))).ToString();
28         }
29         else if (selectFlag.Equals("/"))
30         {
31             Result.Text = (web.division(double.Parse(Num1.Text), double.Parse(Num2.Text))).ToString();
32         }
33     }
34 }

就这样就实现了一个ASP.NET网站访问用Web Service服务实现了两个整数运算的功能.

Web Service(0):用Web Service实现两个整数运算

时间: 2024-08-29 07:30:03

Web Service(0):用Web Service实现两个整数运算的相关文章

说说web 2.0生态圈的那些事

先来说一道面试题吧,“说一下,web 2.0 和web 1.0的区别?” 官方的解释是这样的: Web1.0 的主要特点在于用户通过浏览器获取信息,Web2.0 则更注重用户的交互作用,用户既是网站内容的消费者(浏览者),也是网站内容的制造者.web1.0与web2.0最大的不同就是在web2.0之中个人不再是互联网信息被动的接收者,而是作为一个主动者参与到了互联网的发展之中!用户不再是一个单纯的浏览者而是成为了互联网这块大网的编织者,使用者与传播者!由Web1.0单纯通过网络浏览器浏览html

c语言:输入两个整数m和n,计算需要改变m的二进制表示中的多少位才能得到n

输入两个整数m和n,计算需要改变m的二进制表示中的多少位才能得到n? 解:第一步求这两个数的异或运算,将异或运算结果存起来:第二步统计这个运算结果当中1的位数 程序: #include<stdio.h> int count(int m,int n) { int t,count=0; t = m^n; while (t) { count++; t=t&(t-1); } return count; } int main() { int num1,num2,ret=0; printf(&qu

002:求两个整数的最大公约数和最小公倍数

求最大公约数可采用辗转相除法,其流程如图所示. 最小公倍数就是两个整数的乘积除以其最大公约数. 1 #include <stdio.h> 2 3 int main() 4 { 5 unsigned long a, b, c=0; //两个整数和临时变量 6 unsigned long lcm=0, gcd=0; //最小公倍数和最大公约数 7 8 while( 1 ) 9 { 10 printf("Please input two positive integers(spacebar

两个整数相乘是否超限

如何判断两个整型数相乘是否发生溢出求一个判断方法 1.------------------#include <limits.h> if (INT_MAX / a < b){    overflow;//cout<<"overflow"<<endl;}else{    c = a*b;}------------------- 2.--------------- c = a*b;if( a!=0 && c/a!=b ) overfl

使用MyEclipse9.0开发Web Service

早期使用MyEclipse6.0做WEB服务,里面使用的是XFIRE框架搭建服务平台,后来因为XFIRE更名之后不再更新,导致在最新MyEclipse9.0中使用的是JAX搭建服务. 此文档就是教如何快速的使用9.0开发WEB服务. 步骤一:创建Web Service Project 这里我们使用的框架是JAX-WS.他是目前比较流行和成熟的服务框架. 注意,这里虽然我们选择了JAX-WS框架,但是最让人气愤的是MyEclipse9.0跟本不会导入这个JAR包--汗,JDK里又不自带,只有自己导

WebService的helloworld,服务器端与客户端的Demo(转)----自己建立的Web Project , 而不是Web Service Project,利用WSDD 自己发布

WebService的helloworld,服务器端与客户端的Demo http://blog.csdn.net/angus_17/article/details/8032856 今天突然兴起,想学学webService,然后就找找资料,做了个简单的DEMO.先记录下来,以便日后使用. 首先,先说点理论上的东西. WebService又是一种高级应用,与之前学习的Struts.Spring.Hibernate等框架不同.WebService是面向服务的架构(SOA),看起来像是比SSH框架要大.

Rest风格WEB服务(Rest Style Web Service)的真相

http://blog.csdn.net/jia20003/article/details/8365585 Rest风格WEB服务(Rest Style Web Service)的真相 分类: J2EE2012-12-21 21:55 6103人阅读 评论(2) 收藏 举报 写这篇文章是目的不是介绍Web-Service, 而是从Restful Web Service说起来剖析一下 什么才是真正的Restful Style的架构与协议,从而更好的理解web服务的设计理念与架 构本质. 一:Web

Web Service(1):用Web Service实现客户端图片上传到网站

由于项目需要,通过本地客户端,把图片上传到网站.通过webservice. 这是客户端代码: 1 private void btnimg_Click(object sender, EventArgs e) 2 { 3 this.yanzheng(); 4 mylocalhost.MySoapHeader myheader = new mylocalhost.MySoapHeader();///这是soapheader 5 mylocalhost.MyWebService myService =

Web Reference for a WCF Service has Extra “IdSpecified” Parameter ?

Question: I created a WCF service that exposed a method that has one paramater: public class Service1 : IService1{    public string GetData(int value)    {        return string.Format("You entered: {0}", value);    }} The service has two endpoin