service1.asmx.cs
来自「Csharp实例编程百例.rar」· CS 代码 · 共 92 行
CS
92 行
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
namespace myWebService
{
/// <summary>
/// Service1 的摘要说明。
/// </summary>
public class Service1 : System.Web.Services.WebService
{
public Service1()
{
//CODEGEN:该调用是 ASP.NET Web 服务设计器所必需的
InitializeComponent();
}
//4个WebMethod,Int的加减乘除运算
[WebMethod]
public int Add(int a, int b)
{
return (a + b);
}
[WebMethod]
public int Subtract(int a, int b)
{
return (a - b);
}
[WebMethod]
public int Mutiply(int a, int b)
{
return (a * b);
}
[WebMethod]
public int Divide(int a, int b)
{
if (b == 0)
{
return (-1);
}
return (a / b);
}
#region Component Designer generated code
//Web 服务设计器所必需的
private IContainer components = null;
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
#endregion
// WEB 服务示例
// HelloWorld() 示例服务返回字符串 Hello World
// 若要生成,请取消注释下列行,然后保存并生成项目
// 若要测试此 Web 服务,请按 F5 键
// [WebMethod]
// public string HelloWorld()
// {
// return "Hello World";
// }
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?