⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sumservice.asmx.cs

📁 ASP C#代码实例 适合初学人士学习使用
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;

namespace Example_11_17
{
	/// <summary>
	/// Summary description for SumService.
	/// </summary>
	[WebService(Name="Example_11_17:使用ASP.NET的Web服务——算术Web服务")]
	public class SumService : System.Web.Services.WebService
	{
		public SumService()
		{
			//CODEGEN: This call is required by the ASP.NET Web Services Designer
			InitializeComponent();
		}

		#region Component Designer generated code
		
		//Required by the Web Services Designer 
		private IContainer components = null;
				
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{

		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if(disposing && components != null)
			{
				components.Dispose();
			}
			base.Dispose(disposing);		
		}
		
		#endregion

		// WEB SERVICE EXAMPLE
		// The HelloWorld() example service returns the string Hello World
		// To build, uncomment the following lines then save and build the project
		// To test this web service, press F5

		[WebMethod(Description="求和")]
		public string SUMValue(string a,string b)
		{
		    int	valuea = 0;
			int valueb = 0;
			try
			{
				valuea = Int32.Parse(a);
				valueb = Int32.Parse(b);
			}
			catch
			{
				return("输入的不是整数,请重新输入!!!");
			}
			return((valuea + valueb).ToString());
		}

		[WebMethod(Description="求差")]
		public string SUBValue(string a,string b)
		{
			int	valuea = 0;
			int valueb = 0;
			try
			{
				valuea = Int32.Parse(a);
				valueb = Int32.Parse(b);
			}
			catch
			{
				return("输入的不是整数,请重新输入!!!");
			}
			return((valuea - valueb).ToString());
		}

		[WebMethod(Description="求积")]
		public string MUTLIValue(string a,string b)
		{
			int	valuea = 0;
			int valueb = 0;
			try
			{
				valuea = Int32.Parse(a);
				valueb = Int32.Parse(b);
			}
			catch
			{
				return("输入的不是整数,请重新输入!!!");
			}
			return((valuea * valueb).ToString());
		}

		[WebMethod(Description="求商")]
		public string DIVValue(string a,string b)
		{
			int	valuea = 0;
			int valueb = 0;
			try
			{
				valuea = Int32.Parse(a);
				valueb = Int32.Parse(b);

				if(valueb == 0)
				{
					return("输入错误,除数为0,请重新输入!!!");
				}
			}
			catch
			{
				return("输入的不是整数,请重新输入!!!");
			}
			return((valuea / valueb).ToString());
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -