📄 calculate.cs
字号:
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
/// <summary>
/// Summary description for Calculate
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Calculate : System.Web.Services.WebService {
private double left;
private double right;
public Calculate () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
/* 将请求中的参数转换成double */
private bool convertToDouble(String one, String two)
{
string input1 = Server.HtmlEncode(one);
string input2 = Server.HtmlDecode(two);
if (!String.IsNullOrEmpty(input1) && !String.IsNullOrEmpty(input2))
{
left = Double.Parse(input1);
right = Double.Parse(input2);
}
else
{
return false;
}
return true;
}
/* 加法 */
[WebMethod]
public string add(String one, String two) {
convertToDouble(one, two);
return this.left + this.right + "";
}
/* 乘法 */
[WebMethod]
public string multiply(String one, String two)
{
convertToDouble(one, two);
return this.left * this.right + "";
}
/* 减法 */
[WebMethod]
public string minus(String one, String two)
{
convertToDouble(one, two);
return this.left - this.right + "";
}
/* 除法 */
[WebMethod]
public string divide(String one, String two)
{
convertToDouble(one, two);
if (this.right == 0)
return "undefine operation";
return this.left / this.right + "";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -